184 lines · cpp
1// No PCH:2// RUN: %clang_cc1 -pedantic -std=c++1y -include %s -include %s -verify %s -DNONPCH3// RUN: %clang_cc1 -pedantic -std=c++1y -include %s -include %s -verify %s -DNONPCH -DERROR4//5// With PCH:6// RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch %s -o %t.a -DHEADER17// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.a -emit-pch %s -o %t.b -DHEADER28// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.b -verify %s -DHEADERUSE9 10// RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch -fpch-instantiate-templates %s -o %t.a -DHEADER111// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.a -emit-pch -fpch-instantiate-templates %s -o %t.b -DHEADER212// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.b -verify %s -DHEADERUSE13 14#ifndef ERROR15// expected-no-diagnostics16#endif17 18#ifdef NONPCH19#if !defined(HEADER1)20#define HEADER121#undef HEADER222#undef HEADERUSE23#elif !defined(HEADER2)24#define HEADER225#undef HEADERUSE26#else27#define HEADERUSE28#undef HEADER129#undef HEADER230#endif31#endif32 33 34// *** HEADER1: First header file35#if defined(HEADER1) && !defined(HEADER2) && !defined(HEADERUSE)36 37template<typename T> T var0a = T();38template<typename T> extern T var0b;39 40namespace join {41 template<typename T> T va = T(100);42 template<typename T> extern T vb;43 44 namespace diff_types {45#ifdef ERROR46 template<typename T> extern float err0;47 template<typename T> extern T err1;48#endif49 template<typename T> extern T def;50 }51 52}53 54namespace spec {55 template<typename T> constexpr T va = T(10);56 template<> constexpr float va<float> = 1.5;57 template constexpr int va<int>;58 59 template<typename T> T vb = T();60 template<> constexpr float vb<float> = 1.5;61 62 template<typename T> T vc = T();63 64 template<typename T> constexpr T vd = T(10);65 template<typename T> T* vd<T*> = new T();66}67 68namespace spec_join1 {69 template<typename T> T va = T(10);70#ifdef ERROR71 template<> float va<float>; // expected-note {{previous definition is here}}72#endif73 extern template int va<int>;74 75 template<typename T> T vb = T(10);76#ifdef ERROR77 template<> float vb<float>; // expected-note {{previous definition is here}}78#endif79 80 template<typename T> T vc = T(10);81 82 template<typename T> T vd = T(10);83 template<typename T> extern T* vd<T*>;84}85 86#endif87 88 89// *** HEADER2: Second header file -- including HEADER190#if defined(HEADER2) && !defined(HEADERUSE)91 92namespace join {93 template<typename T> extern T va;94 template<> constexpr float va<float> = 2.5;95 96 template<typename T> T vb = T(100);97 98 namespace diff_types {99#ifdef ERROR100 template<typename T> extern T err0; // expected-error {{redeclaration of 'err0' with a different type: 'T' vs 'float'}} // expected-note@46 {{previous declaration is here}}101 template<typename T> extern float err1; // expected-error {{redeclaration of 'err1' with a different type: 'float' vs 'T'}} // expected-note@47 {{previous declaration is here}}102#endif103 template<typename T> extern T def;104 }105}106 107namespace spec_join1 {108 template<typename T> extern T va;109#ifdef ERROR110 template<> float va<float> = 1.5; // expected-error {{redefinition of 'va<float>'}}111#endif112 extern template int va<int>;113 114#ifdef ERROR115 template<> float vb<float> = 1.5; // expected-error {{redefinition of 'vb<float>'}}116#endif117 template int vb<int>;118 119 template<> float vc<float> = 1.5;120 template int vc<int>;121 122 template<typename T> extern T vd;123 template<typename T> T* vd<T*> = new T();124}125 126#endif127 128// *** HEADERUSE: File using both header files -- including HEADER2129#ifdef HEADERUSE130 131template int var0a<int>;132float fvara = var0a<float>;133 134template<typename T> extern T var0a;135 136template<typename T> T var0b = T();137template int var0b<int>;138float fvarb = var0b<float>;139 140namespace join {141 template const int va<const int>;142 template<> const int va<int> = 50;143 static_assert(va<float> == 2.5, "");144 static_assert(va<int> == 50, "");145 146 template<> constexpr float vb<float> = 2.5;147 template const int vb<const int>;148 static_assert(vb<float> == 2.5, "");149 static_assert(vb<const int> == 100, "");150 151 namespace diff_types {152 template<typename T> T def = T();153 }154 155}156 157namespace spec {158 static_assert(va<float> == 1.5, "");159 static_assert(va<int> == 10, "");160 161 template<typename T> T* vb<T*> = new T();162 int* intpb = vb<int*>;163 static_assert(vb<float> == 1.5, "");164 165 template<typename T> T* vc<T*> = new T();166 template<> constexpr float vc<float> = 1.5;167 int* intpc = vc<int*>;168 static_assert(vc<float> == 1.5, "");169 170 char* intpd = vd<char*>;171}172 173namespace spec_join1 {174 template int va<int>;175 int a = va<int>;176 177 template<typename T> extern T vb;178 int b = vb<int>;179 180 int* intpb = vd<int*>;181}182 183#endif184