blob: d27e9ca93c43ffe9026e32b0bf16a151e4fef3a1 [file] [log] [blame]
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001// Test this without pch.
Richard Smith9a4db032012-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 Kyrtzidis90b715e2010-06-19 19:28:53 +00004
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00005// Test with pch.
Richard Smith9a4db032012-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 -
8// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - | FileCheck %s
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00009
Andy Gibbs8e8fb3b2012-10-19 12:44:48 +000010// expected-no-diagnostics
11
Argyrios Kyrtzidis0e036382010-08-05 09:48:16 +000012// CHECK: define weak_odr void @_ZN2S4IiE1mEv
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +000013// CHECK: define linkonce_odr void @_ZN2S3IiE1mEv
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +000014
15struct A {
16 typedef int type;
17 static void my_f();
18 template <typename T>
19 static T my_templf(T x) { return x; }
20};
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +000021
Douglas Gregor32adc8b2010-10-26 00:51:02 +000022void test(const int (&a6)[17]) {
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +000023 int x = templ_f<int, 5>(3);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +000024
25 S<char, float>::templ();
26 S<int, char>::partial();
27 S<int, float>::explicit_special();
Argyrios Kyrtzidis8dfbd8b2010-06-24 08:57:31 +000028
29 Dep<A>::Ty ty;
30 Dep<A> a;
31 a.f();
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +000032
33 S3<int> s3;
34 s3.m();
Argyrios Kyrtzidisf84cde12010-09-06 19:04:27 +000035
36 TS5 ts(0);
Douglas Gregor32adc8b2010-10-26 00:51:02 +000037
38 S6<const int[17]>::t2 b6 = a6;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +000039}
Argyrios Kyrtzidis0e036382010-08-05 09:48:16 +000040
41template struct S4<int>;
Douglas Gregor7c789c12010-10-29 22:39:52 +000042
43S7<int[5]> s7_5;
Douglas Gregordef03542011-02-04 12:01:24 +000044
45namespace ZeroLengthExplicitTemplateArgs {
46 template void f<X>(X*);
47}
Anders Carlssonb0ca1372011-03-06 18:19:42 +000048
49// This used to overwrite memory and crash.
50namespace Test1 {
51 struct StringHasher {
52 template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) {
53 return 0;
54 }
55 };
56
57 struct CaseFoldingHash {
58 static inline char foldCase(char) {
59 return 0;
60 }
61
62 static unsigned hash(const char* data, unsigned length) {
63 return StringHasher::createHash<char, foldCase>(data, length);
64 }
65 };
66}
Douglas Gregora8e0b972012-03-26 15:52:37 +000067
68template< typename D >
69Foo< D >& Foo< D >::operator=( const Foo& other )
70{
71 return *this;
72}
Richard Smith9a4db032012-09-12 00:56:43 +000073
74namespace 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}