annotate clang/test/SemaTemplate/explicit-instantiation.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions -Wno-dynamic-exception-spec %std_cxx11- %s
150
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 template void *; // expected-error{{expected unqualified-id}}
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 template typedef void f0; // expected-error{{explicit instantiation of typedef}}
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 int v0; // expected-note{{refers here}}
anatofuz
parents:
diff changeset
8 template int v0; // expected-error{{does not refer}}
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 template<typename T>
anatofuz
parents:
diff changeset
11 struct X0 {
anatofuz
parents:
diff changeset
12 static T value;
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 T f0(T x) {
anatofuz
parents:
diff changeset
15 return x + 1; // expected-error{{invalid operands}}
anatofuz
parents:
diff changeset
16 }
anatofuz
parents:
diff changeset
17 T *f0(T *, T *) { return T(); } // expected-warning 0-1 {{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} expected-error 0-1 {{cannot initialize return object of type 'int *' with an rvalue of type 'int'}}
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 template <typename U> T f0(T, U) { return T(); } // expected-note-re {{candidate template ignored: could not match 'int (int, U){{( __attribute__\(\(thiscall\)\))?}}' against 'int (int){{( __attribute__\(\(thiscall\)\))?}} const'}} \
anatofuz
parents:
diff changeset
20 // expected-note {{candidate template ignored: could not match 'int' against 'int *'}}
anatofuz
parents:
diff changeset
21 };
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 template<typename T>
anatofuz
parents:
diff changeset
24 T X0<T>::value; // expected-error{{no matching constructor}}
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 template int X0<int>::value;
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} expected-note 0-1 {{candidate constructor (the implicit move constructor)}}
anatofuz
parents:
diff changeset
29 NotDefaultConstructible(int); // expected-note{{candidate constructor}}
anatofuz
parents:
diff changeset
30 };
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}}
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 template int X0<int>::f0(int);
anatofuz
parents:
diff changeset
35 template int* X0<int>::f0(int*, int*); // expected-note{{in instantiation of member function 'X0<int>::f0' requested here}}
anatofuz
parents:
diff changeset
36 template int X0<int>::f0(int, float);
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 template int X0<int>::f0(int) const; // expected-error{{does not refer}}
anatofuz
parents:
diff changeset
39 template int* X0<int>::f0(int*, float*); // expected-error{{does not refer}}
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 struct X1 { };
anatofuz
parents:
diff changeset
42 typedef int X1::*MemPtr;
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 template MemPtr X0<MemPtr>::f0(MemPtr); // expected-note{{requested here}}
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 struct X2 {
anatofuz
parents:
diff changeset
47 int f0(int); // expected-note{{refers here}}
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 template<typename T> T f1(T) { return T(); }
anatofuz
parents:
diff changeset
50 template<typename T> T* f1(T*) { return 0; }
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 template<typename T, typename U> void f2(T, U*) { } // expected-note{{candidate}}
anatofuz
parents:
diff changeset
53 template<typename T, typename U> void f2(T*, U) { } // expected-note{{candidate}}
anatofuz
parents:
diff changeset
54 };
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 template int X2::f0(int); // expected-error{{not an instantiation}}
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 template int *X2::f1(int *); // okay
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 template void X2::f2(int *, int *); // expected-error{{ambiguous}}
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 template <typename T>
anatofuz
parents:
diff changeset
63 void print_type() {} // expected-note {{candidate template ignored: could not match 'void ()' against 'void (float *)'}}
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 template void print_type<int>();
anatofuz
parents:
diff changeset
66 template void print_type<float>();
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 template <typename T>
anatofuz
parents:
diff changeset
69 void print_type(T *) {} // expected-note {{candidate template ignored: could not match 'void (int *)' against 'void (float *)'}}
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 template void print_type(int*);
anatofuz
parents:
diff changeset
72 template void print_type<int>(float*); // expected-error{{does not refer}}
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 void print_type(double*);
anatofuz
parents:
diff changeset
75 template void print_type<double>(double*);
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 // PR5069
anatofuz
parents:
diff changeset
78 template<int I> void foo0 (int (&)[I + 1]) { }
anatofuz
parents:
diff changeset
79 template void foo0<2> (int (&)[3]);
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 namespace explicit_instantiation_after_implicit_instantiation {
anatofuz
parents:
diff changeset
82 template <int I> struct X0 { static int x; };
anatofuz
parents:
diff changeset
83 template <int I> int X0<I>::x;
anatofuz
parents:
diff changeset
84 void test1() { (void)&X0<1>::x; }
anatofuz
parents:
diff changeset
85 template struct X0<1>;
anatofuz
parents:
diff changeset
86 }
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 template<typename> struct X3 { };
anatofuz
parents:
diff changeset
89 inline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}}
anatofuz
parents:
diff changeset
90 static template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}}
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 namespace PR7622 {
anatofuz
parents:
diff changeset
93 template<typename,typename=int>
anatofuz
parents:
diff changeset
94 struct basic_streambuf;
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 template<typename,typename>
anatofuz
parents:
diff changeset
97 struct basic_streambuf{friend bob<>()}; // expected-error{{no template named 'bob'}} \
anatofuz
parents:
diff changeset
98 // expected-error{{expected member name or ';' after declaration specifiers}}
anatofuz
parents:
diff changeset
99 template struct basic_streambuf<int>;
anatofuz
parents:
diff changeset
100 }
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102 // Test that we do not crash.
anatofuz
parents:
diff changeset
103 class TC1 {
anatofuz
parents:
diff changeset
104 class TC2 {
anatofuz
parents:
diff changeset
105 template
anatofuz
parents:
diff changeset
106 void foo() { } // expected-error{{expected '<' after 'template'}}
anatofuz
parents:
diff changeset
107 };
anatofuz
parents:
diff changeset
108 };
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 namespace PR8020 {
anatofuz
parents:
diff changeset
111 template <typename T> struct X { X() {} };
anatofuz
parents:
diff changeset
112 template<> struct X<int> { X(); };
anatofuz
parents:
diff changeset
113 template X<int>::X() {} // expected-error{{function cannot be defined in an explicit instantiation}}
anatofuz
parents:
diff changeset
114 }
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 namespace PR10086 {
anatofuz
parents:
diff changeset
117 template void foobar(int i) {} // expected-error{{function cannot be defined in an explicit instantiation}}
anatofuz
parents:
diff changeset
118 int func() {
anatofuz
parents:
diff changeset
119 foobar(5);
anatofuz
parents:
diff changeset
120 }
anatofuz
parents:
diff changeset
121 }
anatofuz
parents:
diff changeset
122
anatofuz
parents:
diff changeset
123 namespace undefined_static_data_member {
anatofuz
parents:
diff changeset
124 template<typename T> struct A {
anatofuz
parents:
diff changeset
125 static int a; // expected-note {{here}}
anatofuz
parents:
diff changeset
126 template<typename U> static int b; // expected-note {{here}} expected-warning 0+ {{extension}}
anatofuz
parents:
diff changeset
127 };
anatofuz
parents:
diff changeset
128 struct B {
anatofuz
parents:
diff changeset
129 template<typename U> static int c; // expected-note {{here}} expected-warning 0+ {{extension}}
anatofuz
parents:
diff changeset
130 };
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 template int A<int>::a; // expected-error {{explicit instantiation of undefined static data member 'a' of class template 'undefined_static_data_member::A<int>'}}
anatofuz
parents:
diff changeset
133 template int A<int>::b<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::A<int>::b<int>'}}
anatofuz
parents:
diff changeset
134 template int B::c<int>; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::B::c<int>'}}
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136
anatofuz
parents:
diff changeset
137 template<typename T> struct C {
anatofuz
parents:
diff changeset
138 static int a;
anatofuz
parents:
diff changeset
139 template<typename U> static int b; // expected-warning 0+ {{extension}}
anatofuz
parents:
diff changeset
140 };
anatofuz
parents:
diff changeset
141 struct D {
anatofuz
parents:
diff changeset
142 template<typename U> static int c; // expected-warning 0+ {{extension}}
anatofuz
parents:
diff changeset
143 };
anatofuz
parents:
diff changeset
144 template<typename T> int C<T>::a;
anatofuz
parents:
diff changeset
145 template<typename T> template<typename U> int C<T>::b; // expected-warning 0+ {{extension}}
anatofuz
parents:
diff changeset
146 template<typename U> int D::c; // expected-warning 0+ {{extension}}
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 template int C<int>::a;
anatofuz
parents:
diff changeset
149 template int C<int>::b<int>;
anatofuz
parents:
diff changeset
150 template int D::c<int>;
anatofuz
parents:
diff changeset
151 }
anatofuz
parents:
diff changeset
152
anatofuz
parents:
diff changeset
153 // expected-note@+1 3-4 {{explicit instantiation refers here}}
anatofuz
parents:
diff changeset
154 template <class T> void Foo(T i) throw(T) { throw i; }
anatofuz
parents:
diff changeset
155 // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}}
anatofuz
parents:
diff changeset
156 template void Foo(int a) throw(char);
anatofuz
parents:
diff changeset
157 // expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}}
anatofuz
parents:
diff changeset
158 template void Foo(double a) throw();
anatofuz
parents:
diff changeset
159 // expected-error@+1 1 {{exception specification in explicit instantiation does not match instantiated one}}
anatofuz
parents:
diff changeset
160 template void Foo(long a) throw(long, char);
anatofuz
parents:
diff changeset
161 template void Foo(float a);
anatofuz
parents:
diff changeset
162 #if __cplusplus >= 201103L
anatofuz
parents:
diff changeset
163 // expected-error@+1 0-1 {{exception specification in explicit instantiation does not match instantiated one}}
anatofuz
parents:
diff changeset
164 template void Foo(double a) noexcept;
anatofuz
parents:
diff changeset
165 #endif
anatofuz
parents:
diff changeset
166
anatofuz
parents:
diff changeset
167 #if __cplusplus >= 201103L
anatofuz
parents:
diff changeset
168 namespace PR21942 {
anatofuz
parents:
diff changeset
169 template <int>
anatofuz
parents:
diff changeset
170 struct A {
anatofuz
parents:
diff changeset
171 virtual void foo() final;
anatofuz
parents:
diff changeset
172 };
anatofuz
parents:
diff changeset
173
anatofuz
parents:
diff changeset
174 template <>
anatofuz
parents:
diff changeset
175 void A<0>::foo() {} // expected-note{{overridden virtual function is here}}
anatofuz
parents:
diff changeset
176
anatofuz
parents:
diff changeset
177 struct B : A<0> {
anatofuz
parents:
diff changeset
178 virtual void foo() override; // expected-error{{declaration of 'foo' overrides a 'final' function}}
anatofuz
parents:
diff changeset
179 };
anatofuz
parents:
diff changeset
180 }
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
181
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
182 template<typename T> struct LambdaInDefaultMemberInitInExplicitInstantiation {
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
183 int a = [this] { return a; }();
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
184 };
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
185 template struct LambdaInDefaultMemberInitInExplicitInstantiation<int>;
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
186 LambdaInDefaultMemberInitInExplicitInstantiation<float> x;
150
anatofuz
parents:
diff changeset
187 #endif