1dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis// Test this without pch. 2651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o - 3651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// 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 490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 5dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis// Test with pch. 6651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h 7651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o - 8651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// 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 9a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis 106982bf4d77bc57a85ee173b631729fce673f16efRichard Smith// Test with modules. 11651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// 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 12651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s -ast-dump -o - 130e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// 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 -fmodules-ignore-macro=NO_ERRORS | FileCheck %s 146982bf4d77bc57a85ee173b631729fce673f16efRichard Smith 15ac32d9044b9c1e7492cef929a322d23ce899d276Richard Smith// Test with pch and delayed template parsing. 16651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// 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 17651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -include-pch %t -verify %s -ast-dump -o - 18651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// 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 198e8fb3be5bd78f0564444eca02b404566a5f3b5dAndy Gibbs 20651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: define weak_odr {{.*}}void @_ZN2S4IiE1mEv 21651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: define linkonce_odr {{.*}}void @_ZN2S3IiE1mEv 228dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidisstruct A { 248dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis typedef int type; 258dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static void my_f(); 268dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis template <typename T> 278dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static T my_templf(T x) { return x; } 288dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis}; 29f511ba6277d240bbee1064715da8362a6edee5f3Argyrios Kyrtzidis 3032adc8bd6f05d1e26cc221102e48609da2c446baDouglas Gregorvoid test(const int (&a6)[17]) { 31b24e199fbd17af780ab000c5862d191e4daffc0fArgyrios Kyrtzidis int x = templ_f<int, 5>(3); 32dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 33dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis S<char, float>::templ(); 34dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis S<int, char>::partial(); 35dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis S<int, float>::explicit_special(); 368dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 378dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Dep<A>::Ty ty; 388dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Dep<A> a; 398dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis a.f(); 40a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis 41a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis S3<int> s3; 42a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis s3.m(); 43f84cde1cbc6a6e6c29f20b164af38dffab60366aArgyrios Kyrtzidis 44f84cde1cbc6a6e6c29f20b164af38dffab60366aArgyrios Kyrtzidis TS5 ts(0); 4532adc8bd6f05d1e26cc221102e48609da2c446baDouglas Gregor 4632adc8bd6f05d1e26cc221102e48609da2c446baDouglas Gregor S6<const int[17]>::t2 b6 = a6; 47f511ba6277d240bbee1064715da8362a6edee5f3Argyrios Kyrtzidis} 480e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis 490e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidistemplate struct S4<int>; 507c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 517c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas GregorS7<int[5]> s7_5; 52def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor 53def0354384d9c4431f7b58b664b59896d4623028Douglas Gregornamespace ZeroLengthExplicitTemplateArgs { 54def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor template void f<X>(X*); 55def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor} 56b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson 57b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson// This used to overwrite memory and crash. 58b0ca137bf399d956a3424816c238bc2532250d17Anders Carlssonnamespace Test1 { 59b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson struct StringHasher { 60b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) { 61b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson return 0; 62b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson } 63b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson }; 64b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson 65b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson struct CaseFoldingHash { 66b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson static inline char foldCase(char) { 67b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson return 0; 68b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson } 69b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson 70b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson static unsigned hash(const char* data, unsigned length) { 71b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson return StringHasher::createHash<char, foldCase>(data, length); 72b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson } 73b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson }; 74b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson} 75a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor 76a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregortemplate< typename D > 77a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas GregorFoo< D >& Foo< D >::operator=( const Foo& other ) 78a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor{ 79a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor return *this; 80a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor} 819a4db032ecd991626d236a502e770126db32bd31Richard Smith 829a4db032ecd991626d236a502e770126db32bd31Richard Smithnamespace TestNestedExpansion { 839a4db032ecd991626d236a502e770126db32bd31Richard Smith struct Int { 849a4db032ecd991626d236a502e770126db32bd31Richard Smith Int(int); 859a4db032ecd991626d236a502e770126db32bd31Richard Smith friend Int operator+(Int, Int); 869a4db032ecd991626d236a502e770126db32bd31Richard Smith }; 879a4db032ecd991626d236a502e770126db32bd31Richard Smith Int &g(Int, int, double); 889a4db032ecd991626d236a502e770126db32bd31Richard Smith Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0); 899a4db032ecd991626d236a502e770126db32bd31Richard Smith} 907640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis 917640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidisnamespace rdar13135282 { 927640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis void test() { 937640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis __mt_alloc<> mt = __mt_alloc<>(); 947640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis } 957640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis} 960fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedman 970fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedmanvoid CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> &x) { 980fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedman DependentSpecializedFunc(x); 990fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedman} 100e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith 101e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smithnamespace cyclic_module_load { 102e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith extern std::valarray<int> x; 103e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith std::valarray<int> y(x); 104e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith} 105dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith 106dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith#ifndef NO_ERRORS 107dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith// expected-error@cxx-templates.h:305 {{incomplete}} 108dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithtemplate int local_extern::f<int[]>(); // expected-note {{in instantiation of}} 109dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith#endif 110dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithtemplate int local_extern::g<int[]>(); 111