annotate clang/test/SemaTemplate/explicit-instantiation.cpp @ 221:79ff65ed7e25

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