1f4a2713aSLionel Sambuc // Test this without pch.
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o -
3*0a6a1f1dSLionel Sambuc // 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
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc // Test with pch.
6*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump -o -
8*0a6a1f1dSLionel Sambuc // 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
9f4a2713aSLionel Sambuc
10f4a2713aSLionel Sambuc // Test with modules.
11*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s -ast-dump -o -
13*0a6a1f1dSLionel Sambuc // 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
14f4a2713aSLionel Sambuc
15f4a2713aSLionel Sambuc // Test with pch and delayed template parsing.
16*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // 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
19f4a2713aSLionel Sambuc
20*0a6a1f1dSLionel Sambuc // CHECK: define weak_odr {{.*}}void @_ZN2S4IiE1mEv
21*0a6a1f1dSLionel Sambuc // CHECK: define linkonce_odr {{.*}}void @_ZN2S3IiE1mEv
22f4a2713aSLionel Sambuc
23f4a2713aSLionel Sambuc struct A {
24f4a2713aSLionel Sambuc typedef int type;
25f4a2713aSLionel Sambuc static void my_f();
26f4a2713aSLionel Sambuc template <typename T>
my_templfA27f4a2713aSLionel Sambuc static T my_templf(T x) { return x; }
28f4a2713aSLionel Sambuc };
29f4a2713aSLionel Sambuc
test(const int (& a6)[17])30f4a2713aSLionel Sambuc void test(const int (&a6)[17]) {
31f4a2713aSLionel Sambuc int x = templ_f<int, 5>(3);
32f4a2713aSLionel Sambuc
33f4a2713aSLionel Sambuc S<char, float>::templ();
34f4a2713aSLionel Sambuc S<int, char>::partial();
35f4a2713aSLionel Sambuc S<int, float>::explicit_special();
36f4a2713aSLionel Sambuc
37f4a2713aSLionel Sambuc Dep<A>::Ty ty;
38f4a2713aSLionel Sambuc Dep<A> a;
39f4a2713aSLionel Sambuc a.f();
40f4a2713aSLionel Sambuc
41f4a2713aSLionel Sambuc S3<int> s3;
42f4a2713aSLionel Sambuc s3.m();
43f4a2713aSLionel Sambuc
44f4a2713aSLionel Sambuc TS5 ts(0);
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc S6<const int[17]>::t2 b6 = a6;
47f4a2713aSLionel Sambuc }
48f4a2713aSLionel Sambuc
49f4a2713aSLionel Sambuc template struct S4<int>;
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambuc S7<int[5]> s7_5;
52f4a2713aSLionel Sambuc
53f4a2713aSLionel Sambuc namespace ZeroLengthExplicitTemplateArgs {
54f4a2713aSLionel Sambuc template void f<X>(X*);
55f4a2713aSLionel Sambuc }
56f4a2713aSLionel Sambuc
57f4a2713aSLionel Sambuc // This used to overwrite memory and crash.
58f4a2713aSLionel Sambuc namespace Test1 {
59f4a2713aSLionel Sambuc struct StringHasher {
createHashTest1::StringHasher60f4a2713aSLionel Sambuc template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) {
61f4a2713aSLionel Sambuc return 0;
62f4a2713aSLionel Sambuc }
63f4a2713aSLionel Sambuc };
64f4a2713aSLionel Sambuc
65f4a2713aSLionel Sambuc struct CaseFoldingHash {
foldCaseTest1::CaseFoldingHash66f4a2713aSLionel Sambuc static inline char foldCase(char) {
67f4a2713aSLionel Sambuc return 0;
68f4a2713aSLionel Sambuc }
69f4a2713aSLionel Sambuc
hashTest1::CaseFoldingHash70f4a2713aSLionel Sambuc static unsigned hash(const char* data, unsigned length) {
71f4a2713aSLionel Sambuc return StringHasher::createHash<char, foldCase>(data, length);
72f4a2713aSLionel Sambuc }
73f4a2713aSLionel Sambuc };
74f4a2713aSLionel Sambuc }
75f4a2713aSLionel Sambuc
76f4a2713aSLionel Sambuc template< typename D >
operator =(const Foo & other)77f4a2713aSLionel Sambuc Foo< D >& Foo< D >::operator=( const Foo& other )
78f4a2713aSLionel Sambuc {
79f4a2713aSLionel Sambuc return *this;
80f4a2713aSLionel Sambuc }
81f4a2713aSLionel Sambuc
82f4a2713aSLionel Sambuc namespace TestNestedExpansion {
83f4a2713aSLionel Sambuc struct Int {
84f4a2713aSLionel Sambuc Int(int);
85f4a2713aSLionel Sambuc friend Int operator+(Int, Int);
86f4a2713aSLionel Sambuc };
87f4a2713aSLionel Sambuc Int &g(Int, int, double);
88f4a2713aSLionel Sambuc Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0);
89f4a2713aSLionel Sambuc }
90f4a2713aSLionel Sambuc
91f4a2713aSLionel Sambuc namespace rdar13135282 {
test()92f4a2713aSLionel Sambuc void test() {
93f4a2713aSLionel Sambuc __mt_alloc<> mt = __mt_alloc<>();
94f4a2713aSLionel Sambuc }
95f4a2713aSLionel Sambuc }
96f4a2713aSLionel Sambuc
CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> & x)97f4a2713aSLionel Sambuc void CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> &x) {
98f4a2713aSLionel Sambuc DependentSpecializedFunc(x);
99f4a2713aSLionel Sambuc }
100f4a2713aSLionel Sambuc
101f4a2713aSLionel Sambuc namespace cyclic_module_load {
102f4a2713aSLionel Sambuc extern std::valarray<int> x;
103f4a2713aSLionel Sambuc std::valarray<int> y(x);
104f4a2713aSLionel Sambuc }
105f4a2713aSLionel Sambuc
106f4a2713aSLionel Sambuc #ifndef NO_ERRORS
107f4a2713aSLionel Sambuc // expected-error@cxx-templates.h:305 {{incomplete}}
108f4a2713aSLionel Sambuc template int local_extern::f<int[]>(); // expected-note {{in instantiation of}}
109f4a2713aSLionel Sambuc #endif
110f4a2713aSLionel Sambuc template int local_extern::g<int[]>();
111