1 // Test this without pch.
2 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s
3 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s
6 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h
7 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t -verify %s
8 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize -DNO_ERRORS | FileCheck %s
11 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -x c++-header -emit-pch -o %t %S/cxx-templates.h
12 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s
13 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize -DNO_ERRORS -fmodules-ignore-macro=NO_ERRORS | FileCheck %s
15 // Test with pch and delayed template parsing.
16 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h
17 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -include-pch %t -verify %s
18 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -include-pch %t %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s
20 // Test with pch and template instantiation in the pch.
21 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fpch-instantiate-templates -x c++-header -emit-pch -o %t %S/cxx-templates.h
22 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t -verify %s
23 // RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s
25 // CHECK: define weak_odr {{.*}}void @_ZN2S4IiE1mEv
26 // CHECK: define linkonce_odr {{.*}}void @_ZN2S3IiE1mEv
32 static T
my_templf(T x
) { return x
; }
35 void test(const int (&a6
)[17]) {
36 int x
= templ_f
<int, 5>(3);
38 S
<char, float>::templ();
39 S
<int, char>::partial();
40 S
<int, float>::explicit_special();
51 S6
<const int[17]>::t2 b6
= a6
;
54 template struct S4
<int>;
58 namespace ZeroLengthExplicitTemplateArgs
{
59 template void f
<X
>(X
*);
62 // This used to overwrite memory and crash.
65 template<typename T
, char Converter(T
)> static inline unsigned createHash(const T
*, unsigned) {
70 struct CaseFoldingHash
{
71 static inline char foldCase(char) {
75 static unsigned hash(const char* data
, unsigned length
) {
76 return StringHasher::createHash
<char, foldCase
>(data
, length
);
81 template< typename D
>
82 Foo
< D
>& Foo
< D
>::operator=( const Foo
& other
)
87 namespace TestNestedExpansion
{
90 friend Int
operator+(Int
, Int
);
92 Int
&g(Int
, int, double);
93 Int
&test
= NestedExpansion
<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0);
96 namespace rdar13135282
{
98 __mt_alloc
<> mt
= __mt_alloc
<>();
102 void CallDependentSpecializedFunc(DependentSpecializedFuncClass
<int> &x
) {
103 DependentSpecializedFunc(x
);
106 namespace cyclic_module_load
{
107 extern std::valarray
<int> x
;
108 std::valarray
<int> y(x
);
112 // expected-error@cxx-templates.h:304 {{incomplete}}
113 template int local_extern::f
<int[]>(); // expected-note {{in instantiation of}}
115 template int local_extern::g
<int[]>();
117 namespace MemberSpecializationLocation
{
119 // expected-note@cxx-templates.h:* {{previous}}
120 template<> float A
<int>::n
; // expected-error {{redeclaration of 'n' with a different type}}
125 // https://bugs.llvm.org/show_bug.cgi?id=34728
128 // Verify with several TemplateParmDecl kinds, using PCH (incl. modules).
129 int z1
= func1(/*ignored*/2.718);
130 int z2
= func2(/*ignored*/3.142);
132 Container
<int> c
= func3(tmp3
);
135 // Return value is meaningless. Just "use" all these values to avoid
136 // warning about unused vars / values.
139 } // end namespace PR34728
141 namespace ClassScopeExplicitSpecializations
{
142 // FIXME: It's unclear these warnings (and the behavior they're describing)
143 // are desirable. These explicit instantiations could meaningfully
144 // instantiate the explicit specializations defined in the primary template.
145 template int A
<3>::f
<0>() const; // expected-warning {{has no effect}}
146 template int A
<3>::f
<1>() const;
147 template int A
<4>::f
<0>() const; // expected-warning {{has no effect}}
148 template int A
<4>::f
<1>() const;
149 // expected-note@cxx-templates.h:402 2{{here}}
151 static_assert(A
<0>().f
<0>() == 4, "");
152 static_assert(A
<0>().f
<1>() == 5, "");
153 static_assert(A
<0>().f
<2>() == 3, "");
154 static_assert(A
<1>().f
<0>() == 2, "");
155 static_assert(A
<1>().f
<1>() == 1, "");
156 static_assert(A
<1>().f
<2>() == 1, "");
157 static_assert(A
<2>().f
<0>() == 2, "");
158 static_assert(A
<2>().f
<1>() == 1, "");
159 static_assert(A
<3>().f
<0>() == 2, "");
160 static_assert(A
<3>().f
<1>() == 1, "");
161 static_assert(A
<4>().f
<0>() == 2, "");
162 static_assert(A
<4>().f
<1>() == 1, "");
165 namespace DependentMemberExpr
{
167 // This used to mark 'f' invalid without producing any diagnostic. That's a
168 // little hard to detect, but we can make sure that constexpr evaluation
169 // fails when it should.
170 static_assert(A
<int>().f() == 1); // expected-error {{static assertion failed}} \
171 // expected-note {{evaluates to '0 == 1'}}
175 namespace DependentTemplateName
{
177 template <class T
> struct Member
;
181 getWithIdentifier
<HasMember
>();
185 namespace ClassTemplateCycle
{