| Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 1 | // Test this without pch. | 
| Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o - | 
|  | 3 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s | 
| Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4 |  | 
| Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5 | // Test with pch. | 
| Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 6 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h | 
|  | 7 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump  -o - | 
|  | 8 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize -DNO_ERRORS | FileCheck %s | 
| Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 9 |  | 
| Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 10 | // Test with modules. | 
| Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 11 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -x c++-header -emit-pch -o %t %S/cxx-templates.h | 
|  | 12 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s -ast-dump  -o - | 
|  | 13 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize -DNO_ERRORS | FileCheck %s | 
| Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 14 |  | 
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 15 | // Test with pch and delayed template parsing. | 
| Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 16 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h | 
|  | 17 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -include-pch %t -verify %s -ast-dump  -o - | 
|  | 18 | // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -include-pch %t %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s | 
| Andy Gibbs | c6e68da | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 19 |  | 
| Rafael Espindola | 3497069 | 2013-12-12 16:07:11 +0000 | [diff] [blame] | 20 | // CHECK: define weak_odr {{.*}}void @_ZN2S4IiE1mEv | 
|  | 21 | // CHECK: define linkonce_odr {{.*}}void @_ZN2S3IiE1mEv | 
| Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 22 |  | 
|  | 23 | struct A { | 
|  | 24 | typedef int type; | 
|  | 25 | static void my_f(); | 
|  | 26 | template <typename T> | 
|  | 27 | static T my_templf(T x) { return x; } | 
|  | 28 | }; | 
| Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 29 |  | 
| Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 30 | void test(const int (&a6)[17]) { | 
| Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 31 | int x = templ_f<int, 5>(3); | 
| Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 32 |  | 
|  | 33 | S<char, float>::templ(); | 
|  | 34 | S<int, char>::partial(); | 
|  | 35 | S<int, float>::explicit_special(); | 
| Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 36 |  | 
|  | 37 | Dep<A>::Ty ty; | 
|  | 38 | Dep<A> a; | 
|  | 39 | a.f(); | 
| Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 40 |  | 
|  | 41 | S3<int> s3; | 
|  | 42 | s3.m(); | 
| Argyrios Kyrtzidis | d05f3e3 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 43 |  | 
|  | 44 | TS5 ts(0); | 
| Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 45 |  | 
|  | 46 | S6<const int[17]>::t2 b6 = a6; | 
| Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 47 | } | 
| Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 48 |  | 
|  | 49 | template struct S4<int>; | 
| Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 50 |  | 
|  | 51 | S7<int[5]> s7_5; | 
| Douglas Gregor | 87866ce | 2011-02-04 12:01:24 +0000 | [diff] [blame] | 52 |  | 
|  | 53 | namespace ZeroLengthExplicitTemplateArgs { | 
|  | 54 | template void f<X>(X*); | 
|  | 55 | } | 
| Anders Carlsson | 80756f6 | 2011-03-06 18:19:42 +0000 | [diff] [blame] | 56 |  | 
|  | 57 | // This used to overwrite memory and crash. | 
|  | 58 | namespace Test1 { | 
|  | 59 | struct StringHasher { | 
|  | 60 | template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) { | 
|  | 61 | return 0; | 
|  | 62 | } | 
|  | 63 | }; | 
|  | 64 |  | 
|  | 65 | struct CaseFoldingHash { | 
|  | 66 | static inline char foldCase(char) { | 
|  | 67 | return 0; | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | static unsigned hash(const char* data, unsigned length) { | 
|  | 71 | return StringHasher::createHash<char, foldCase>(data, length); | 
|  | 72 | } | 
|  | 73 | }; | 
|  | 74 | } | 
| Douglas Gregor | 9f21889 | 2012-03-26 15:52:37 +0000 | [diff] [blame] | 75 |  | 
|  | 76 | template< typename D > | 
|  | 77 | Foo< D >& Foo< D >::operator=( const Foo& other ) | 
|  | 78 | { | 
|  | 79 | return *this; | 
|  | 80 | } | 
| Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 81 |  | 
|  | 82 | namespace TestNestedExpansion { | 
|  | 83 | struct Int { | 
|  | 84 | Int(int); | 
|  | 85 | friend Int operator+(Int, Int); | 
|  | 86 | }; | 
|  | 87 | Int &g(Int, int, double); | 
|  | 88 | Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0); | 
|  | 89 | } | 
| Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 90 |  | 
|  | 91 | namespace rdar13135282 { | 
|  | 92 | void test() { | 
|  | 93 | __mt_alloc<> mt = __mt_alloc<>(); | 
|  | 94 | } | 
|  | 95 | } | 
| Eli Friedman | f796cf1 | 2013-06-19 01:38:21 +0000 | [diff] [blame] | 96 |  | 
|  | 97 | void CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> &x) { | 
|  | 98 | DependentSpecializedFunc(x); | 
|  | 99 | } | 
| Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 100 |  | 
|  | 101 | namespace cyclic_module_load { | 
|  | 102 | extern std::valarray<int> x; | 
|  | 103 | std::valarray<int> y(x); | 
|  | 104 | } | 
| Richard Smith | 1c34fb7 | 2013-08-13 18:18:50 +0000 | [diff] [blame] | 105 |  | 
|  | 106 | #ifndef NO_ERRORS | 
|  | 107 | // expected-error@cxx-templates.h:305 {{incomplete}} | 
|  | 108 | template int local_extern::f<int[]>(); // expected-note {{in instantiation of}} | 
|  | 109 | #endif | 
|  | 110 | template int local_extern::g<int[]>(); |