1dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis// Test this without pch. 29a4db032ecd991626d236a502e770126db32bd31Richard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o - 39a4db032ecd991626d236a502e770126db32bd31Richard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s 490b715e0df34eae2b50b9b43ec60828ed31dcf94Argyrios Kyrtzidis 5dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis// Test with pch. 69a4db032ecd991626d236a502e770126db32bd31Richard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h 79a4db032ecd991626d236a502e770126db32bd31Richard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o - 8f396ad9b1fa0c74c9db16a8158c3882c9db774e2Richard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s 9a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis 106982bf4d77bc57a85ee173b631729fce673f16efRichard Smith// Test with modules. 116982bf4d77bc57a85ee173b631729fce673f16efRichard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -x c++-header -emit-pch -o %t %S/cxx-templates.h 126982bf4d77bc57a85ee173b631729fce673f16efRichard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s -ast-dump -o - 136982bf4d77bc57a85ee173b631729fce673f16efRichard Smith// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s 146982bf4d77bc57a85ee173b631729fce673f16efRichard Smith 158e8fb3be5bd78f0564444eca02b404566a5f3b5dAndy Gibbs// expected-no-diagnostics 168e8fb3be5bd78f0564444eca02b404566a5f3b5dAndy Gibbs 170e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis// CHECK: define weak_odr void @_ZN2S4IiE1mEv 18a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis// CHECK: define linkonce_odr void @_ZN2S3IiE1mEv 198dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 208dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidisstruct A { 218dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis typedef int type; 228dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static void my_f(); 238dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis template <typename T> 248dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static T my_templf(T x) { return x; } 258dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis}; 26f511ba6277d240bbee1064715da8362a6edee5f3Argyrios Kyrtzidis 2732adc8bd6f05d1e26cc221102e48609da2c446baDouglas Gregorvoid test(const int (&a6)[17]) { 28b24e199fbd17af780ab000c5862d191e4daffc0fArgyrios Kyrtzidis int x = templ_f<int, 5>(3); 29dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis 30dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis S<char, float>::templ(); 31dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis S<int, char>::partial(); 32dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis S<int, float>::explicit_special(); 338dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis 348dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Dep<A>::Ty ty; 358dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis Dep<A> a; 368dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis a.f(); 37a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis 38a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis S3<int> s3; 39a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis s3.m(); 40f84cde1cbc6a6e6c29f20b164af38dffab60366aArgyrios Kyrtzidis 41f84cde1cbc6a6e6c29f20b164af38dffab60366aArgyrios Kyrtzidis TS5 ts(0); 4232adc8bd6f05d1e26cc221102e48609da2c446baDouglas Gregor 4332adc8bd6f05d1e26cc221102e48609da2c446baDouglas Gregor S6<const int[17]>::t2 b6 = a6; 44f511ba6277d240bbee1064715da8362a6edee5f3Argyrios Kyrtzidis} 450e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidis 460e0363866792b309d70e9c8e92b4c239773af89cArgyrios Kyrtzidistemplate struct S4<int>; 477c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor 487c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas GregorS7<int[5]> s7_5; 49def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor 50def0354384d9c4431f7b58b664b59896d4623028Douglas Gregornamespace ZeroLengthExplicitTemplateArgs { 51def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor template void f<X>(X*); 52def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor} 53b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson 54b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson// This used to overwrite memory and crash. 55b0ca137bf399d956a3424816c238bc2532250d17Anders Carlssonnamespace Test1 { 56b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson struct StringHasher { 57b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) { 58b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson return 0; 59b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson } 60b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson }; 61b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson 62b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson struct CaseFoldingHash { 63b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson static inline char foldCase(char) { 64b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson return 0; 65b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson } 66b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson 67b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson static unsigned hash(const char* data, unsigned length) { 68b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson return StringHasher::createHash<char, foldCase>(data, length); 69b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson } 70b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson }; 71b0ca137bf399d956a3424816c238bc2532250d17Anders Carlsson} 72a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor 73a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregortemplate< typename D > 74a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas GregorFoo< D >& Foo< D >::operator=( const Foo& other ) 75a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor{ 76a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor return *this; 77a8e0b978d63c52e39c002fbf014ce553374fedcfDouglas Gregor} 789a4db032ecd991626d236a502e770126db32bd31Richard Smith 799a4db032ecd991626d236a502e770126db32bd31Richard Smithnamespace TestNestedExpansion { 809a4db032ecd991626d236a502e770126db32bd31Richard Smith struct Int { 819a4db032ecd991626d236a502e770126db32bd31Richard Smith Int(int); 829a4db032ecd991626d236a502e770126db32bd31Richard Smith friend Int operator+(Int, Int); 839a4db032ecd991626d236a502e770126db32bd31Richard Smith }; 849a4db032ecd991626d236a502e770126db32bd31Richard Smith Int &g(Int, int, double); 859a4db032ecd991626d236a502e770126db32bd31Richard Smith Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0); 869a4db032ecd991626d236a502e770126db32bd31Richard Smith} 877640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis 887640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidisnamespace rdar13135282 { 897640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis void test() { 907640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis __mt_alloc<> mt = __mt_alloc<>(); 917640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis } 927640b02a561fd2b2c58a227b262b0c1ba93622aeArgyrios Kyrtzidis} 930fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedman 940fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedmanvoid CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> &x) { 950fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedman DependentSpecializedFunc(x); 960fa93cecf26a157dec7def11ffa4080ae75fe559Eli Friedman} 97e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith 98e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smithnamespace cyclic_module_load { 99e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith extern std::valarray<int> x; 100e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith std::valarray<int> y(x); 101e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith} 102