blob: f57245e7c1c1fb0a8810148a354f28a07ca13e35 [file] [log] [blame]
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001// Test this without pch.
Richard Smithb15fe3a2012-09-12 00:56:43 +00002// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o -
3// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00004
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00005// Test with pch.
Richard Smithb15fe3a2012-09-12 00:56:43 +00006// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h
7// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o -
Richard Smith5205a8c2013-04-01 20:22:16 +00008// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00009
Richard Smithfeb3e1a2013-06-28 04:37:53 +000010// Test with modules.
11// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -x c++-header -emit-pch -o %t %S/cxx-templates.h
12// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s -ast-dump -o -
13// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s
14
Andy Gibbsc6e68da2012-10-19 12:44:48 +000015// expected-no-diagnostics
16
Argyrios Kyrtzidis7f76d112010-08-05 09:48:16 +000017// CHECK: define weak_odr void @_ZN2S4IiE1mEv
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +000018// CHECK: define linkonce_odr void @_ZN2S3IiE1mEv
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +000019
20struct A {
21 typedef int type;
22 static void my_f();
23 template <typename T>
24 static T my_templf(T x) { return x; }
25};
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000026
Douglas Gregorf86c9392010-10-26 00:51:02 +000027void test(const int (&a6)[17]) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +000028 int x = templ_f<int, 5>(3);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +000029
30 S<char, float>::templ();
31 S<int, char>::partial();
32 S<int, float>::explicit_special();
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +000033
34 Dep<A>::Ty ty;
35 Dep<A> a;
36 a.f();
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +000037
38 S3<int> s3;
39 s3.m();
Argyrios Kyrtzidisd05f3e32010-09-06 19:04:27 +000040
41 TS5 ts(0);
Douglas Gregorf86c9392010-10-26 00:51:02 +000042
43 S6<const int[17]>::t2 b6 = a6;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000044}
Argyrios Kyrtzidis7f76d112010-08-05 09:48:16 +000045
46template struct S4<int>;
Douglas Gregord4c5ed02010-10-29 22:39:52 +000047
48S7<int[5]> s7_5;
Douglas Gregor87866ce2011-02-04 12:01:24 +000049
50namespace ZeroLengthExplicitTemplateArgs {
51 template void f<X>(X*);
52}
Anders Carlsson80756f62011-03-06 18:19:42 +000053
54// This used to overwrite memory and crash.
55namespace Test1 {
56 struct StringHasher {
57 template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) {
58 return 0;
59 }
60 };
61
62 struct CaseFoldingHash {
63 static inline char foldCase(char) {
64 return 0;
65 }
66
67 static unsigned hash(const char* data, unsigned length) {
68 return StringHasher::createHash<char, foldCase>(data, length);
69 }
70 };
71}
Douglas Gregor9f218892012-03-26 15:52:37 +000072
73template< typename D >
74Foo< D >& Foo< D >::operator=( const Foo& other )
75{
76 return *this;
77}
Richard Smithb15fe3a2012-09-12 00:56:43 +000078
79namespace TestNestedExpansion {
80 struct Int {
81 Int(int);
82 friend Int operator+(Int, Int);
83 };
84 Int &g(Int, int, double);
85 Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0);
86}
Argyrios Kyrtzidis83a6e3b2013-02-16 00:48:59 +000087
88namespace rdar13135282 {
89 void test() {
90 __mt_alloc<> mt = __mt_alloc<>();
91 }
92}
Eli Friedmanf796cf12013-06-19 01:38:21 +000093
94void CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> &x) {
95 DependentSpecializedFunc(x);
96}
Richard Smith95d99302013-07-13 02:00:19 +000097
98namespace cyclic_module_load {
99 extern std::valarray<int> x;
100 std::valarray<int> y(x);
101}