1 // Test this without pch.
2 // 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
4
5 // Test with pch.
6 // 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 -
8 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s
9
10 // expected-no-diagnostics
11
12 // CHECK: define weak_odr void @_ZN2S4IiE1mEv
13 // CHECK: define linkonce_odr void @_ZN2S3IiE1mEv
14
15 struct A {
16 typedef int type;
17 static void my_f();
18 template <typename T>
my_templfA19 static T my_templf(T x) { return x; }
20 };
21
test(const int (& a6)[17])22 void test(const int (&a6)[17]) {
23 int x = templ_f<int, 5>(3);
24
25 S<char, float>::templ();
26 S<int, char>::partial();
27 S<int, float>::explicit_special();
28
29 Dep<A>::Ty ty;
30 Dep<A> a;
31 a.f();
32
33 S3<int> s3;
34 s3.m();
35
36 TS5 ts(0);
37
38 S6<const int[17]>::t2 b6 = a6;
39 }
40
41 template struct S4<int>;
42
43 S7<int[5]> s7_5;
44
45 namespace ZeroLengthExplicitTemplateArgs {
46 template void f<X>(X*);
47 }
48
49 // This used to overwrite memory and crash.
50 namespace Test1 {
51 struct StringHasher {
createHashTest1::StringHasher52 template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) {
53 return 0;
54 }
55 };
56
57 struct CaseFoldingHash {
foldCaseTest1::CaseFoldingHash58 static inline char foldCase(char) {
59 return 0;
60 }
61
hashTest1::CaseFoldingHash62 static unsigned hash(const char* data, unsigned length) {
63 return StringHasher::createHash<char, foldCase>(data, length);
64 }
65 };
66 }
67
68 template< typename D >
operator =(const Foo & other)69 Foo< D >& Foo< D >::operator=( const Foo& other )
70 {
71 return *this;
72 }
73
74 namespace TestNestedExpansion {
75 struct Int {
76 Int(int);
77 friend Int operator+(Int, Int);
78 };
79 Int &g(Int, int, double);
80 Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0);
81 }
82
83 namespace rdar13135282 {
test()84 void test() {
85 __mt_alloc<> mt = __mt_alloc<>();
86 }
87 }
88