Debian Codegraph @

clang/test/CXX/drs/cwg2xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
7
8 // FIXME: diagnostic above is emitted only on Windows platforms
9 // PR13819 -- __SIZE_TYPE__ is incompatible.
10 typedef __SIZE_TYPE__ size_t;
11 // cxx98-error@-1 0-1 {{'long long' is a C++11 extension}}
12
13 #if __cplusplus == 199711L
14 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
15 // cxx98-error@-1 {{variadic macros are a C99 feature}}
16 #endif
17
18 #if __cplusplus == 199711L
19 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
20 #else
21 #define __enable_constant_folding
22 #endif
23
24 namespace cwg200 { // cwg200: dup 214
25 template <class T> T f(int);
26 template <class T, class U> T f(U) = delete;
27 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
28
29 void g() {
30 f<int>(1);
31 }
32 }
33
34 // cwg201 is in cwg201.cpp
35
36 namespace cwg202 { // cwg202: 3.1
37 template<typename T> T f();
38 template<int (*g)()> struct X {
39 static_assert(__enable_constant_folding(g == &f<int>), "");
40 };
41 template struct X<f>;
42 }
43
44 // cwg204: sup 820
45
46 namespace cwg206 { // cwg206: yes
47 struct S; // #cwg206-S
48 template<typename T> struct Q { S s; };
49 // expected-error@-1 {{field has incomplete type 'S'}}
50 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
51 template<typename T> void f() { S s; }
52 // expected-error@-1 {{variable has incomplete type 'S'}}
53 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
54 }
55
56 namespace cwg207 { // cwg207: yes
57 class A {
58 protected:
59 static void f() {}
60 };
61 class B : A {
62 public:
63 using A::f;
64 void g() {
65 A::f();
66 f();
67 }
68 };
69 }
70
71 // cwg208 FIXME: write codegen test
72
73 namespace cwg209 { // cwg209: 3.2
74 class A {
75 void f(); // #cwg209-A-f
76 };
77 class B {
78 friend void A::f();
79 // expected-error@-1 {{friend function 'f' is a private member of 'cwg209::A'}}
80 // expected-note@#cwg209-A-f {{implicitly declared private here}}
81 };
82 }
83
84 // cwg210 is in cwg210.cpp
85
86 namespace cwg211 { // cwg211: yes
87 struct A {
88 A() try {
89 throw 0;
90 } catch (...) {
91 return;
92 // expected-error@-1 {{return in the catch of a function try block of a constructor is illegal}}
93 }
94 };
95 }
96
97 namespace cwg213 { // cwg213: yes
98 template <class T> struct A : T {
99 void h(T t) {
100 char &r1 = f(t);
101 int &r2 = g(t);
102 // expected-error@-1 {{explicit qualification required to use member 'g' from dependent base class}}
103 // expected-note@#cwg213-instantiation {{in instantiation of member function 'cwg213::A<cwg213::B>::h' requested here}}
104 // expected-note@#cwg213-B-g {{member is declared here}}
105 }
106 };
107 struct B {
108 int &f(B);
109 int &g(B); // #cwg213-B-g
110 };
111 char &f(B);
112
113 template void A<B>::h(B); // #cwg213-instantiation
114 }
115
116 namespace cwg214 { // cwg214: yes
117 template<typename T, typename U> T checked_cast(U from) { U::error; }
118 template<typename T, typename U> T checked_cast(U *from);
119 class C {};
120 void foo(int *arg) { checked_cast<const C *>(arg); }
121
122 template<typename T> T f(int);
123 template<typename T, typename U> T f(U) { T::error; }
124 void g() {
125 f<int>(1);
126 }
127 }
128
129 namespace cwg215 { // cwg215: 2.9
130 template<typename T> class X {
131 friend void T::foo();
132 int n;
133 };
134 struct Y {
135 void foo() { (void)+X<Y>().n; }
136 };
137 }
138
139 namespace cwg216 { // cwg216: no
140 // FIXME: Should reject this: 'f' has linkage but its type does not,
141 // and 'f' is odr-used but not defined in this TU.
142 typedef enum { e } *E;
143 void f(E);
144 void g(E e) { f(e); }
145
146 struct S {
147 // FIXME: Should reject this: 'f' has linkage but its type does not,
148 // and 'f' is odr-used but not defined in this TU.
149 typedef enum { e } *E;
150 void f(E);
151 };
152 void g(S s, S::E e) { s.f(e); }
153 }
154
155 namespace cwg217 { // cwg217: yes
156 template<typename T> struct S {
157 void f(int);
158 };
159 template<typename T> void S<T>::f(int = 0) {}
160 // expected-error@-1 {{default arguments cannot be added to an out-of-line definition of a member of a class template}}
161 }
162
163 namespace cwg218 { // cwg218: yes
164 // NB: also dup 405
165 namespace A {
166 struct S {};
167 void f(S);
168 }
169 namespace B {
170 struct S {};
171 void f(S);
172 }
173
174 struct C {
175 int f;
176 void test1(A::S as) { f(as); }
177 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
178 void test2(A::S as) { void f(); f(as); }
179 // expected-error@-1 {{too many arguments to function call, expected 0, have 1}}
180 // expected-note@-2 {{'f' declared here}}
181 void test3(A::S as) { using A::f; f(as); } // ok
182 void test4(A::S as) { using B::f; f(as); } // ok
183 void test5(A::S as) { int f; f(as); }
184 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
185 void test6(A::S as) { struct f {}; (void) f(as); }
186 // expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}}
187 // expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}}
188 // since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}}
189 // expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
190 };
191
192 namespace D {
193 struct S {};
194 struct X { void operator()(S); } f;
195 }
196 void testD(D::S ds) { f(ds); }
197 // expected-error@-1 {{use of undeclared identifier 'f'}}
198
199 namespace E {
200 struct S {};
201 struct f { f(S); };
202 }
203 void testE(E::S es) { f(es); }
204 // expected-error@-1 {{use of undeclared identifier 'f'}}
205
206 namespace F {
207 struct S {
208 template<typename T> friend void f(S, T) {}
209 };
210 }
211 void testF(F::S fs) { f(fs, 0); }
212
213 namespace G {
214 namespace X {
215 int f;
216 struct A {};
217 }
218 namespace Y {
219 template<typename T> void f(T);
220 struct B {};
221 }
222 template<typename A, typename B> struct C {};
223 }
224 void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }
225 }
226
227 // cwg219: na
228 // cwg220: na
229
230 namespace cwg221 { // cwg221: 3.6
231 struct A { // #cwg221-S
232 A &operator=(int&); // #cwg221-S-copy-assign
233 A &operator+=(int&);
234 static A &operator=(A&, double&);
235 // expected-error@-1 {{overloaded 'operator=' cannot be a static member function}}
236 static A &operator+=(A&, double&);
237 // expected-error@-1 {{overloaded 'operator+=' cannot be a static member function}}
238 friend A &operator=(A&, char&);
239 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
240 friend A &operator+=(A&, char&);
241 };
242 A &operator=(A&, float&);
243 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
244 A &operator+=(A&, float&);
245
246 void test(A a, int n, char c, float f) {
247 a = n;
248 a += n;
249 a = c;
250 // expected-error@-1 {{no viable overloaded '='}}
251 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'char' to 'int &' for 1st argument}}
252 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'char' to 'A' for 1st argument}}
253 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'char' to 'const A' for 1st argument}}
254 a += c;
255 a = f;
256 // expected-error@-1 {{no viable overloaded '='}}
257 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'float' to 'int &' for 1st argument}}
258 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'float' to 'A' for 1st argument}}
259 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'float' to 'const A' for 1st argument}}
260 a += f;
261 }
262 }
263
264 namespace cwg222 { // cwg222: dup 637
265 void f(int a, int b, int c, int *x) {
266 #pragma clang diagnostic push
267 #pragma clang diagnostic warning "-Wunsequenced"
268 void((a += b) += c);
269 void((a += b) + (a += c));
270 // expected-warning@-1 {{multiple unsequenced modifications to 'a'}}
271
272 x[a++] = a;
273 // cxx98-14-warning@-1 {{unsequenced modification and access to 'a'}}
274
275 a = b = 0; // ok, read and write of 'b' are sequenced
276
277 a = (b = a++);
278 // cxx98-14-warning@-1 {{multiple unsequenced modifications to 'a'}}
279 a = (b = ++a);
280 #pragma clang diagnostic pop
281 }
282 }
283
284 // cwg223: na
285
286 namespace cwg224 { // cwg224: 16
287 namespace example1 {
288 template <class T> class A {
289 typedef int type;
290 A::type a;
291 A<T>::type b;
292 A<T*>::type c;
293 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
294 ::cwg224::example1::A<T>::type d;
295
296 class B {
297 typedef int type;
298
299 A::type a;
300 A<T>::type b;
301 A<T*>::type c;
302 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
303 ::cwg224::example1::A<T>::type d;
304
305 B::type e;
306 A<T>::B::type f;
307 A<T*>::B::type g;
308 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::B::type; implicit 'typename' is a C++20 extension}}
309 typename A<T*>::B::type h;
310 };
311 };
312
313 template <class T> class A<T*> {
314 typedef int type;
315 A<T*>::type a;
316 A<T>::type b;
317 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T>::type; implicit 'typename' is a C++20 extension}}
318 };
319
320 template <class T1, class T2, int I> struct B {
321 typedef int type;
322 B<T1, T2, I>::type b1;
323 B<T2, T1, I>::type b2;
324 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<T2, T1, I>::type; implicit 'typename' is a C++20 extension}}
325
326 typedef T1 my_T1;
327 static const int my_I = I;
328 static const int my_I2 = I+0;
329 static const int my_I3 = my_I;
330 B<my_T1, T2, my_I>::type b3;
331 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I>::type; implicit 'typename' is a C++20 extension}}
332 B<my_T1, T2, my_I2>::type b4;
333 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I2>::type; implicit 'typename' is a C++20 extension}}
334 B<my_T1, T2, my_I3>::type b5;
335 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I3>::type; implicit 'typename' is a C++20 extension}}
336 };
337 }
338
339 namespace example2 {
340 template <int, typename T> struct X { typedef T type; };
341 template <class T> class A {
342 static const int i = 5;
343 X<i, int>::type w;
344 X<A::i, char>::type x;
345 X<A<T>::i, double>::type y;
346 X<A<T*>::i, long>::type z;
347 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name X<A<T *>::i, long>::type; implicit 'typename' is a C++20 extension}}
348 int f();
349 };
350 template <class T> int A<T>::f() {
351 return i;
352 }
353 }
354 }
355
356 // cwg225: yes
357 template<typename T> void cwg225_f(T t) { cwg225_g(t); }
358 // expected-error@-1 {{call to function 'cwg225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}
359 // expected-note@#cwg225-f {{in instantiation of function template specialization 'cwg225_f<int>' requested here}}
360 // expected-note@#cwg225-g {{'cwg225_g' should be declared prior to the call site}}
361 void cwg225_g(int); // #cwg225-g
362 template void cwg225_f(int); // #cwg225-f
363
364 namespace cwg226 { // cwg226: no
365 // FIXME: This appears to be wrong: default arguments for function templates
366 // are listed as a defect (in c++98) not an extension. EDG accepts them in
367 // strict c++98 mode.
368 template<typename T = void> void f() {}
369 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
370 template<typename T> struct S {
371 template<typename U = void> void g();
372 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
373 template<typename U> struct X;
374 template<typename U> void h();
375 };
376 template<typename T> template<typename U> void S<T>::g() {}
377 template<typename T> template<typename U = void> struct S<T>::X {};
378 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
379 template<typename T> template<typename U = void> void S<T>::h() {}
380 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
381
382 template<typename> void friend_h();
383 struct A {
384 // FIXME: This is ill-formed.
385 template<typename=void> struct friend_B;
386 // FIXME: f, h, and i are ill-formed.
387 // f is ill-formed because it is not a definition.
388 // h and i are ill-formed because they are not the only declarations of the
389 // function in the translation unit.
390 template<typename=void> void friend_f();
391 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
392 template<typename=void> void friend_g() {}
393 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
394 template<typename=void> void friend_h() {}
395 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
396 template<typename=void> void friend_i() {}
397 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
398 };
399 template<typename> void friend_i();
400
401 template<typename=void, typename X> void foo(X) {}
402 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
403 template<typename=void, typename X> struct Foo {};
404 // expected-error@-1 {{template parameter missing a default argument}}
405 // expected-note@-2 {{previous default template argument defined here}}
406
407 template<typename=void, typename X, typename, typename Y> int foo(X, Y);
408 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
409 template<typename, typename X, typename=void, typename Y> int foo(X, Y);
410 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
411 int x = foo(0, 0);
412 }
413
414 void cwg227(bool b) { // cwg227: yes
415 if (b)
416 int n;
417 else
418 int n;
419 }
420
421 namespace cwg228 { // cwg228: yes
422 template <class T> struct X {
423 void f();
424 };
425 template <class T> struct Y {
426 void g(X<T> x) { x.template X<T>::f(); }
427 };
428 }
429
430 namespace cwg229 { // cwg229: 2.9
431 template<typename T> void f();
432 template<typename T> void f<T*>() {}
433 // expected-error@-1 {{function template partial specialization is not allowed}}
434 template<> void f<int>() {}
435 }
436
437 namespace cwg230 { // cwg230: 3.0
438 struct S {
439 S() { f(); }
440 // expected-warning@-1 {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'cwg230::S'}}
441 // expected-note@#cwg230-f {{'f' declared here}}
442 virtual void f() = 0; // #cwg230-f
443 };
444 }
445
446 namespace cwg231 { // cwg231: yes
447 namespace outer {
448 namespace inner {
449 int i; // #cwg231-i
450 }
451 void f() { using namespace inner; }
452 int j = i;
453 // expected-error@-1 {{use of undeclared identifier 'i'; did you mean 'inner::i'?}}
454 // expected-note@#cwg231-i {{'inner::i' declared here}}
455 }
456 }
457
458 // cwg234: na
459 // cwg235: na
460
461 namespace cwg236 { // cwg236: 3.2
462 void *p = int();
463 // cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}
464 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}}
465 }
466
467 namespace cwg237 { // cwg237: dup 470
468 template<typename T> struct A { void f() { T::error; } };
469 template<typename T> struct B : A<T> {};
470 template struct B<int>; // ok
471 }
472
473 namespace cwg239 { // cwg239: yes
474 namespace NS {
475 class T {};
476 void f(T);
477 float &g(T, int);
478 }
479 NS::T parm;
480 int &g(NS::T, float);
481 int main() {
482 f(parm);
483 float &r = g(parm, 1);
484 extern int &g(NS::T, float);
485 int &s = g(parm, 1);
486 }
487 }
488
489 // cwg240: dup 616
490
491 namespace cwg241 { // cwg241: yes
492 namespace A {
493 struct B {};
494 template <int X> void f(); // #cwg241-A-f
495 template <int X> void g(B);
496 }
497 namespace C {
498 template <class T> void f(T t); // #cwg241-C-f
499 template <class T> void g(T t); // #cwg241-C-g
500 }
501 void h(A::B b) {
502 f<3>(b);
503 // expected-error@-1 {{no matching function for call to 'f'}}
504 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
505 // cxx98-17-error@-3 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}
506 g<3>(b);
507 // cxx98-17-error@-1 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}
508 A::f<3>(b);
509 // expected-error@-1 {{no matching function for call to 'f'}}
510 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
511 A::g<3>(b);
512 C::f<3>(b);
513 // expected-error@-1 {{no matching function for call to 'f'}}
514 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
515 C::g<3>(b);
516 // expected-error@-1 {{no matching function for call to 'g'}}
517 // expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
518 using C::f;
519 using C::g;
520 f<3>(b);
521 // expected-error@-1 {{no matching function for call to 'f'}}
522 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
523 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
524 g<3>(b);
525 }
526 }
527
528 namespace cwg243 { // cwg243: yes
529 struct B;
530 struct A {
531 A(B); // #cwg243-A
532 };
533 struct B {
534 operator A() = delete; // #cwg243-B
535 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
536 } b;
537 A a1(b);
538 A a2 = b;
539 // expected-error@-1 {{conversion from 'struct B' to 'A' is ambiguous}}
540 // expected-note@#cwg243-A {{candidate constructor}}
541 // expected-note@#cwg243-B {{candidate function has been explicitly deleted}}
542 }
543
544 namespace cwg244 { // cwg244: 11
545 // NB: this test is reused by cwg399
546 struct B {}; // #cwg244-B
547 struct D : B {};
548
549 D D_object;
550 typedef B B_alias;
551 B* B_ptr = &D_object;
552
553 void f() {
554 D_object.~B();
555 // expected-error@-1 {{destructor type 'cwg244::B' in object destruction expression does not match the type 'D' of the object being destroyed}}
556 // expected-note@#cwg244-B {{type 'cwg244::B' found by destructor name lookup}}
557 D_object.B::~B();
558 D_object.D::~B(); // FIXME: Missing diagnostic for this.
559 B_ptr->~B();
560 B_ptr->~B_alias();
561 B_ptr->B_alias::~B();
562 B_ptr->B_alias::~B_alias();
563 B_ptr->cwg244::~B();
564 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
565 B_ptr->cwg244::~B_alias();
566 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
567 }
568
569 template<typename T, typename U>
570 void f(T *B_ptr, U D_object) {
571 D_object.~B(); // FIXME: Missing diagnostic for this.
572 D_object.B::~B();
573 D_object.D::~B(); // FIXME: Missing diagnostic for this.
574 B_ptr->~B();
575 B_ptr->~B_alias();
576 B_ptr->B_alias::~B();
577 B_ptr->B_alias::~B_alias();
578 B_ptr->cwg244::~B();
579 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
580 B_ptr->cwg244::~B_alias();
581 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
582 }
583 template void f<B, D>(B*, D);
584
585 namespace N {
586 template<typename T> struct E {};
587 typedef E<int> F;
588 }
589 void g(N::F f) {
590 typedef N::F G; // #cwg244-G
591 f.~G();
592 f.G::~E();
593 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
594 f.G::~F();
595 // expected-error@-1 {{undeclared identifier 'F' in destructor name}}
596 f.G::~G();
597 // This is technically ill-formed; E is looked up in 'N::' and names the
598 // class template, not the injected-class-name of the class. But that's
599 // probably a bug in the standard.
600 f.N::F::~E();
601 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
602 // This is valid; we look up the second F in the same scope in which we
603 // found the first one, that is, 'N::'.
604 f.N::F::~F();
605 // This is technically ill-formed; G is looked up in 'N::' and is not found.
606 // Rejecting this seems correct, but most compilers accept, so we do also.
607 f.N::F::~G();
608 // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
609 // expected-note@#cwg244-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}
610 }
611
612 // Bizarrely, compilers perform lookup in the scope for qualified destructor
613 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
614 // this.
615 namespace QualifiedLookupInScope {
616 namespace N {
617 template <typename> struct S { struct Inner {}; };
618 }
619 template <typename U> void f(typename N::S<U>::Inner *p) {
620 typedef typename N::S<U>::Inner T;
621 p->::cwg244::QualifiedLookupInScope::N::S<U>::Inner::~T();
622 // expected-error@-1 {{no type named 'T' in 'cwg244::QualifiedLookupInScope::N::S<int>'}}
623 // expected-note@#cwg244-f {{in instantiation of function template specialization 'cwg244::QualifiedLookupInScope::f<int>' requested here}}
624 }
625 template void f<int>(N::S<int>::Inner *); // #cwg244-f
626
627 template <typename U> void g(U *p) {
628 typedef U T;
629 p->T::~T();
630 p->U::~T();
631 p->::cwg244::QualifiedLookupInScope::N::S<int>::Inner::~T();
632 // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}
633 }
634 template void g(N::S<int>::Inner *);
635 }
636 }
637
638 namespace cwg245 { // cwg245: yes
639 struct S {
640 enum E {}; // #cwg245-E
641 class E *p;
642 // expected-error@-1 {{use of 'E' with tag type that does not match previous declaration}}
643 // expected-note@#cwg245-E {{previous use is here}}
644 };
645 }
646
647 namespace cwg246 { // cwg246: 3.2
648 struct S {
649 S() try { // #cwg246-try
650 throw 0;
651 X: ;
652 } catch (int) {
653 goto X;
654 // expected-error@-1 {{cannot jump from this goto statement to its label}}
655 // expected-note@#cwg246-try {{jump bypasses initialization of try block}}
656 }
657 };
658 }
659
660 namespace cwg247 { // cwg247: yes
661 struct A {};
662 struct B : A {
663 void f();
664 void f(int);
665 };
666 void (A::*f)() = (void (A::*)())&B::f;
667
668 struct C {
669 void f();
670 void f(int);
671 };
672 struct D : C {};
673 void (C::*g)() = &D::f;
674 void (D::*h)() = &D::f;
675
676 struct E {
677 void f();
678 };
679 struct F : E {
680 using E::f;
681 void f(int);
682 };
683 void (F::*i)() = &F::f;
684 }
685
686 namespace cwg248 { // cwg248: sup P1949
687 int \u040d\u040e = 0;
688 }
689
690 namespace cwg249 { // cwg249: yes
691 template<typename T> struct X { void f(); };
692 template<typename T> void X<T>::f() {}
693 }
694
695 namespace cwg250 { // cwg250: yes
696 typedef void (*FPtr)(double x[]);
697
698 template<int I> void f(double x[]);
699 FPtr fp = &f<3>;
700
701 template<int I = 3> void g(double x[]);
702 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
703 FPtr gp = &g<>;
704 }
705
706 namespace cwg252 { // cwg252: 3.1
707 struct A {
708 void operator delete(void*); // #cwg252-A
709 };
710 struct B {
711 void operator delete(void*); // #cwg252-B
712 };
713 struct C : A, B {
714 virtual ~C();
715 };
716 C::~C() {}
717 // expected-error@-1 {{member 'operator delete' found in multiple base classes of different types}}
718 // expected-note@#cwg252-A {{member found by ambiguous name lookup}}
719 // expected-note@#cwg252-B {{member found by ambiguous name lookup}}
720
721 struct D {
722 void operator delete(void*, int); // #cwg252-D
723 virtual ~D();
724 };
725 D::~D() {}
726 // expected-error@-1 {{no suitable member 'operator delete' in 'D'}}
727 // expected-note@#cwg252-D {{member 'operator delete' declared here}}
728
729 struct E {
730 void operator delete(void*, int);
731 void operator delete(void*) = delete; // #cwg252-E
732 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
733 virtual ~E();
734 };
735 E::~E() {}
736 // expected-error@-1 {{attempt to use a deleted function}}
737 // expected-note@#cwg252-E {{'operator delete' has been explicitly marked deleted here}}
738
739 struct F {
740 // If both functions are available, the first one is a placement delete.
741 void operator delete(void*, size_t);
742 void operator delete(void*) = delete; // #cwg252-F
743 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
744 virtual ~F();
745 };
746 F::~F() {}
747 // expected-error@-1 {{attempt to use a deleted function}}
748 // expected-note@#cwg252-F {{'operator delete' has been explicitly marked deleted here}}
749
750 struct G {
751 void operator delete(void*, size_t);
752 virtual ~G();
753 };
754 G::~G() {}
755 }
756
757 namespace cwg254 { // cwg254: 2.9
758 template<typename T> struct A {
759 typedef typename T::type type; // ok even if this is a typedef-name, because
760 // it's not an elaborated-type-specifier
761 typedef struct T::type foo;
762 // expected-error@-1 {{typedef 'type' cannot be referenced with the 'struct' specifier}}
763 // expected-note@#cwg254-instantiation {{in instantiation of template class 'cwg254::A<cwg254::C>' requested here}}
764 // expected-note@#cwg254-C {{declared here}}
765 };
766 struct B { struct type {}; };
767 struct C { typedef struct {} type; }; // #cwg254-C
768 A<B>::type n;
769 A<C>::type n; // #cwg254-instantiation
770 }
771
772 namespace cwg255 { // cwg255: yes
773 struct S {
774 void operator delete(void *){};
775 void operator delete(void *, int){};
776 };
777 void f(S *p) { delete p; }
778 } // namespace cwg255
779
780 // cwg256: dup 624
781
782 namespace cwg257 { // cwg257: 3.4
783 struct A { A(int); }; // #cwg257-A
784 struct B : virtual A {
785 B() {}
786 virtual void f() = 0;
787 };
788 struct C : B {
789 C() {}
790 };
791 struct D : B {
792 D() {}
793 // expected-error@-1 {{constructor for 'cwg257::D' must explicitly initialize the base class 'A' which does not have a default constructor}}
794 // expected-note@#cwg257-A {{'cwg257::A' declared here}}
795 void f();
796 };
797 }
798
799 namespace cwg258 { // cwg258: 2.8
800 struct A {
801 void f(const int);
802 template<typename> void g(int);
803 float &h() const;
804 };
805 struct B : A {
806 using A::f;
807 using A::g;
808 using A::h;
809 int &f(int);
810 template<int> int &g(int); // #cwg258-B-g
811 int &h();
812 } b;
813 int &w = b.f(0);
814 int &x = b.g<int>(0);
815 // expected-error@-1 {{no matching member function for call to 'g'}}
816 // expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
817 int &y = b.h();
818 float &z = const_cast<const B&>(b).h();
819
820 struct C {
821 virtual void f(const int) = 0;
822 };
823 struct D : C {
824 void f(int);
825 } d;
826
827 struct E {
828 virtual void f() = 0; // #cwg258-E-f
829 };
830 struct F : E {
831 void f() const {}
832 } f;
833 // expected-error@-1 {{variable type 'struct F' is an abstract class}}
834 // expected-note@#cwg258-E-f {{unimplemented pure virtual method 'f' in 'F'}}
835 }
836
837 namespace cwg259 { // cwg259: 4
838 template<typename T> struct A {};
839 template struct A<int>; // #cwg259-A-int
840 template struct A<int>;
841 // expected-error@-1 {{duplicate explicit instantiation of 'A<int>'}}
842 // expected-note@#cwg259-A-int {{previous explicit instantiation is here}}
843
844 template<> struct A<float>; // #cwg259-A-float
845 template struct A<float>;
846 // expected-warning@-1 {{explicit instantiation of 'A<float>' that occurs after an explicit specialization has no effect}}
847 // expected-note@#cwg259-A-float {{previous template specialization is here}}
848
849 template struct A<char>; // #cwg259-A-char
850 template<> struct A<char>;
851 // expected-error@-1 {{explicit specialization of 'cwg259::A<char>' after instantiation}}
852 // expected-note@#cwg259-A-char {{explicit instantiation first required here}}
853
854 template<> struct A<double>;
855 template<> struct A<double>;
856 template<> struct A<double> {}; // #cwg259-A-double
857 template<> struct A<double> {};
858 // expected-error@-1 {{redefinition of 'A<double>'}}
859 // expected-note@#cwg259-A-double {{previous definition is here}}
860
861 template<typename T> struct B; // #cwg259-B
862 template struct B<int>;
863 // expected-error@-1 {{explicit instantiation of undefined template 'cwg259::B<int>'}}
864 // expected-note@#cwg259-B {{template is declared here}}
865
866 template<> struct B<float>; // #cwg259-B-float
867 template struct B<float>;
868 // expected-warning@-1 {{explicit instantiation of 'B<float>' that occurs after an explicit specialization has no effect}}
869 // expected-note@#cwg259-B-float {{previous template specialization is here}}
870 }
871
872 // FIXME: When cwg260 is resolved, also add tests for CWG507.
873
874 namespace cwg261 { // cwg261: no
875 #pragma clang diagnostic push
876 #pragma clang diagnostic warning "-Wused-but-marked-unused"
877
878 // FIXME: This is ill-formed, with a diagnostic required, because operator new
879 // and operator delete are inline and odr-used, but not defined in this
880 // translation unit.
881 // We're also missing the -Wused-but-marked-unused diagnostic here.
882 struct A {
883 inline void *operator new(size_t) __attribute__((unused));
884 inline void operator delete(void*) __attribute__((unused));
885 A() {}
886 };
887
888 // FIXME: This is ill-formed, with a required diagnostic, for the same
889 // reason.
890 struct B {
891 inline void operator delete(void*) __attribute__((unused));
892 ~B() {}
893 };
894 struct C {
895 inline void operator delete(void*) __attribute__((unused));
896 virtual ~C() {}
897 // expected-warning@-1 {{'operator delete' was marked unused but was used}}
898 };
899
900 struct D {
901 inline void operator delete(void*) __attribute__((unused));
902 };
903 void h() { C::operator delete(0); }
904 // expected-warning@-1 {{'operator delete' was marked unused but was used}}
905
906 #pragma clang diagnostic pop
907 }
908
909 namespace cwg262 { // cwg262: yes
910 int f(int = 0, ...);
911 int k = f();
912 int l = f(0);
913 int m = f(0, 0);
914 }
915
916 namespace cwg263 { // cwg263: 3.3
917 struct X {};
918 struct Y {
919 #if __cplusplus < 201103L
920 friend X::X() throw();
921 friend X::~X() throw();
922 #elif __cplusplus <= 201703L
923 friend constexpr X::X() noexcept;
924 friend X::~X();
925 #else
926 friend constexpr X::X() noexcept;
927 friend constexpr X::~X();
928 #endif
929 Y::Y();
930 // expected-error@-1 {{extra qualification on member 'Y'}}
931 Y::~Y();
932 // expected-error@-1 {{extra qualification on member '~Y'}}
933 };
934 }
935
936 // cwg265: dup 353
937 // cwg266: na
938 // cwg269: na
939 // cwg270: na
940
941 namespace cwg272 { // cwg272: yes
942 struct X {
943 void f() {
944 this->~X();
945 X::~X();
946 ~X();
947 // expected-error@-1 {{invalid argument type 'X' to unary expression}}
948 }
949 };
950 }
951
952 #include <stdarg.h>
953 #include <stddef.h>
954 namespace cwg273 { // cwg273: yes
955 struct A {
956 int n;
957 };
958 void operator&(A);
959 void f(A a, ...) {
960 offsetof(A, n);
961 va_list val;
962 va_start(val, a);
963 va_end(val);
964 }
965 }
966
967 // cwg274: na
968
969 namespace cwg275 { // cwg275: no
970 namespace N {
971 template <class T> void f(T) {} // #cwg275-N-f
972 template <class T> void g(T) {} // #cwg275-N-g
973 template <> void f(int);
974 template <> void f(char);
975 template <> void f(double);
976 template <> void g(char);
977 }
978
979 using namespace N;
980
981 namespace M {
982 template <> void N::f(char) {}
983 // expected-error@-1 {{cannot define or redeclare 'f' here because namespace 'M' does not enclose namespace 'N'}}
984 template <class T> void g(T) {}
985 template <> void g(char) {}
986 // FIXME: this should be rejected in c++98 too
987 template void f(long);
988 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
989 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
990 // FIXME: this should be rejected in c++98 too
991 template void N::f(unsigned long);
992 // since-cxx11-error@-1 {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
993 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
994 template void h(long);
995 // expected-error@-1 {{explicit instantiation of 'h' does not refer to a function template, variable template, member function, member class, or static data member}}
996 template <> void f(double) {}
997 // expected-error@-1 {{no function template matches function template specialization 'f'}}
998 }
999
1000 template <class T> void g(T) {} // #cwg275-g
1001
1002 template <> void N::f(char) {}
1003 template <> void f(int) {}
1004 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1005
1006 // FIXME: this should be rejected in c++98 too
1007 template void f(short);
1008 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
1009 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
1010 template void N::f(unsigned short);
1011
1012 // FIXME: this should probably be valid. the wording from the issue
1013 // doesn't clarify this, but it follows from the usual rules.
1014 template void g(int);
1015 // expected-error@-1 {{partial ordering for explicit instantiation of 'g' is ambiguous}}
1016 // expected-note@#cwg275-g {{explicit instantiation candidate function 'cwg275::g<int>' template here [with T = int]}}
1017 // expected-note@#cwg275-N-g {{explicit instantiation candidate function 'cwg275::N::g<int>' template here [with T = int]}}
1018
1019 // FIXME: likewise, this should also be valid.
1020 template<typename T> void f(T) {} // #cwg275-f
1021 template void f(short);
1022 // expected-error@-1 {{partial ordering for explicit instantiation of 'f' is ambiguous}}
1023 // expected-note@#cwg275-f {{explicit instantiation candidate function 'cwg275::f<short>' template here [with T = short]}}
1024 // expected-note@#cwg275-N-f {{explicit instantiation candidate function 'cwg275::N::f<short>' template here [with T = short]}}
1025 }
1026
1027 // cwg276: na
1028
1029 namespace cwg277 { // cwg277: 3.1
1030 typedef int *intp;
1031 int *p = intp();
1032 static_assert(__enable_constant_folding(!intp()), "");
1033 }
1034
1035 namespace cwg280 { // cwg280: 2.9
1036 typedef void f0();
1037 typedef void f1(int);
1038 typedef void f2(int, int);
1039 typedef void f3(int, int, int);
1040 struct A {
1041 operator f1*(); // #cwg280-A-f1
1042 operator f2*();
1043 };
1044 struct B {
1045 operator f0*(); // #cwg280-B-f0
1046 private:
1047 operator f3*(); // #cwg280-B-f3
1048 };
1049 struct C {
1050 operator f0*(); // #cwg280-C-f0
1051 operator f1*(); // #cwg280-C-f1
1052 operator f2*(); // #cwg280-C-f2
1053 operator f3*(); // #cwg280-C-f3
1054 };
1055 struct D : private A, B { // #cwg280-D
1056 operator f2*(); // #cwg280-D-f2
1057 } d;
1058 struct E : C, D {} e;
1059 void g() {
1060 d(); // ok, public
1061 d(0);
1062 // expected-error@-1 {{'operator void (*)(int)' is a private member of 'cwg280::A'}}
1063 // expected-note@#cwg280-D {{constrained by private inheritance here}}
1064 // expected-note@#cwg280-A-f1 {{member is declared here}}
1065 d(0, 0); // ok, suppressed by member in D
1066 d(0, 0, 0);
1067 // expected-error@-1 {{'operator void (*)(int, int, int)' is a private member of 'cwg280::B'}}
1068 // expected-note@#cwg280-B-f3 {{declared private here}}
1069 e();
1070 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1071 // expected-note@#cwg280-B-f0 {{conversion candidate of type 'void (*)()'}}
1072 // expected-note@#cwg280-C-f0 {{conversion candidate of type 'void (*)()'}}
1073 e(0);
1074 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1075 // expected-note@#cwg280-A-f1 {{conversion candidate of type 'void (*)(int)'}}
1076 // expected-note@#cwg280-C-f1 {{conversion candidate of type 'void (*)(int)'}}
1077 e(0, 0);
1078 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1079 // expected-note@#cwg280-C-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1080 // expected-note@#cwg280-D-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1081 e(0, 0, 0);
1082 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1083 // expected-note@#cwg280-B-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1084 // expected-note@#cwg280-C-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1085 }
1086 }
1087
1088 namespace cwg281 { // cwg281: no
1089 void a();
1090 inline void b();
1091
1092 void d();
1093 inline void e();
1094
1095 struct S {
1096 friend inline void a(); // FIXME: ill-formed
1097 friend inline void b();
1098 friend inline void c(); // FIXME: ill-formed
1099 friend inline void d() {}
1100 friend inline void e() {}
1101 friend inline void f() {}
1102 };
1103 }
1104
1105 namespace cwg283 { // cwg283: yes
1106 template<typename T> // #cwg283-template
1107 struct S {
1108 friend class T;
1109 // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1110 // expected-note@#cwg283-template {{template parameter is declared here}}
1111 class T;
1112 // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1113 // expected-note@#cwg283-template {{template parameter is declared here}}
1114 };
1115 }
1116
1117 namespace cwg284 { // cwg284: no
1118 namespace A {
1119 struct X;
1120 enum Y {};
1121 class Z {};
1122 }
1123 namespace B {
1124 struct W;
1125 using A::X;
1126 using A::Y;
1127 using A::Z;
1128 }
1129 struct B::V {};
1130 // expected-error@-1 {{no struct named 'V' in namespace 'cwg284::B'}}
1131 struct B::W {};
1132 struct B::X {}; // FIXME: ill-formed
1133 enum B::Y e; // ok per cwg417
1134 class B::Z z; // ok per cwg417
1135
1136 struct C {
1137 struct X;
1138 enum Y {};
1139 class Z {};
1140 };
1141 struct D : C {
1142 struct W;
1143 using C::X;
1144 using C::Y;
1145 using C::Z;
1146 };
1147 struct D::V {};
1148 // expected-error@-1 {{no struct named 'V' in 'cwg284::D'}}
1149 struct D::W {};
1150 struct D::X {}; // FIXME: ill-formed
1151 enum D::Y e2; // ok per cwg417
1152 class D::Z z2; // ok per cwg417
1153 }
1154
1155 namespace cwg285 { // cwg285: yes
1156 template<typename T> void f(T, int); // #cwg285-f-T-int
1157 template<typename T> void f(int, T); // #cwg285-f-int-T
1158 template<> void f<int>(int, int) {}
1159 // expected-error@-1 {{function template specialization 'f' ambiguously refers to more than one function template; explicitly specify additional template arguments to identify a particular function template}}
1160 // expected-note@#cwg285-f-int-T {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1161 // expected-note@#cwg285-f-T-int {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1162 }
1163
1164 namespace cwg286 { // cwg286: 2.8
1165 template<class T> struct A {
1166 class C {
1167 template<class T2> struct B {}; // #cwg286-B
1168 };
1169 };
1170
1171 template<class T>
1172 template<class T2>
1173 struct A<T>::C::B<T2*> { };
1174
1175 A<short>::C::B<int*> absip;
1176 // expected-error@-1 {{'B' is a private member of 'cwg286::A<short>::C'}}
1177 // expected-note@#cwg286-B {{implicitly declared private here}}
1178 }
1179
1180 // cwg288: na
1181
1182 namespace cwg289 { // cwg289: yes
1183 struct A; // #cwg289-A
1184 struct B : A {};
1185 // expected-error@-1 {{base class has incomplete type}}
1186 // expected-note@#cwg289-A {{forward declaration of 'cwg289::A'}}
1187
1188 template<typename T> struct C { typename T::error error; };
1189 // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
1190 // expected-note@#cwg289-C-int {{in instantiation of template class 'cwg289::C<int>' requested here}}
1191 struct D : C<int> {}; // #cwg289-C-int
1192 }
1193
1194 // cwg290: na
1195 // cwg291: dup 391
1196 // cwg292 is in cwg292.cpp
1197
1198 namespace cwg294 { // cwg294: no
1199 void f() throw(int);
1200 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1201 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1202 int main() {
1203 (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before
1204 // FIXME: since-cxx17-error@-1 {{static_cast from 'void (*)() throw(int)' to 'void (*)() throw()' is not allowed}}
1205 //
1206 // Irony: the above is valid in C++17 and beyond, but that's exactly when
1207 // we reject it. In C++14 and before, this is ill-formed because an
1208 // exception-specification is not permitted in a type-id. In C++17, this is
1209 // valid because it's the inverse of a standard conversion sequence
1210 // containing a function pointer conversion. (Well, it's actually not valid
1211 // yet, as a static_cast is not permitted to reverse a function pointer
1212 // conversion, but that is being changed by core issue).
1213 (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before
1214 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1215 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1216
1217 void (*p)() throw() = f;
1218 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1219 // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void () throw(int)': different exception specifications}}
1220 void (*q)() throw(int) = f;
1221 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1222 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1223 }
1224 }
1225
1226 namespace cwg295 { // cwg295: 3.7
1227 typedef int f();
1228 const f g;
1229 // expected-warning@-1 {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}}
1230 f &r = g;
1231 template<typename T> struct X {
1232 const T &f;
1233 };
1234 X<f> x = {g};
1235
1236 typedef int U();
1237 typedef const U U;
1238 // expected-warning@-1 {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}}
1239
1240 typedef int (*V)();
1241 typedef volatile U *V;
1242 // expected-warning@-1 {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}}
1243 }
1244
1245 namespace cwg296 { // cwg296: yes
1246 struct A {
1247 static operator int() { return 0; }
1248 // expected-error@-1 {{conversion function must be a non-static member function}}
1249 };
1250 }
1251
1252 namespace cwg298 { // cwg298: 3.1
1253 struct A {
1254 typedef int type;
1255 A();
1256 ~A();
1257 };
1258 typedef A B; // #cwg298-B
1259 typedef const A C; // #cwg298-C
1260
1261 A::type i1;
1262 B::type i2;
1263 C::type i3;
1264
1265 struct A a;
1266 struct B b;
1267 // expected-error@-1 {{typedef 'B' cannot be referenced with the 'struct' specifier}}
1268 // expected-note@#cwg298-B {{declared here}}
1269 struct C c;
1270 // expected-error@-1 {{typedef 'C' cannot be referenced with the 'struct' specifier}}
1271 // expected-note@#cwg298-C {{declared here}}
1272
1273 B::B() {}
1274 // expected-error@-1 {{a type specifier is required for all declarations}}
1275 B::A() {} // ok
1276 C::~C() {}
1277 // expected-error@-1 {{destructor cannot be declared using a typedef 'C' (aka 'const cwg298::A') of the class name}}
1278
1279 typedef struct D E; // #cwg298-E
1280 struct E {};
1281 // expected-error@-1 {{definition of type 'E' conflicts with typedef of the same name}}
1282 // expected-note@#cwg298-E {{'E' declared here}}
1283
1284 struct F {
1285 ~F();
1286 };
1287 typedef const F G;
1288 G::~F() {} // ok
1289 }
1290
1291 namespace cwg299 { // cwg299: 2.8 c++11
1292 struct S {
1293 operator int();
1294 };
1295 struct T {
1296 operator int(); // #cwg299-int
1297 operator unsigned short(); // #cwg299-ushort
1298 };
1299 // FIXME: should this apply to c++98 mode?
1300 int *p = new int[S()];
1301 // cxx98-error@-1 {{implicit conversion from array size expression of type 'S' to integral type 'int' is a C++11 extension}}
1302 int *q = new int[T()]; // #cwg299-q
1303 // cxx98-11-error@#cwg299-q {{ambiguous conversion of array size expression of type 'T' to an integral or enumeration type}}
1304 // cxx98-11-note@#cwg299-int {{conversion to integral type 'int' declared here}}
1305 // cxx98-11-note@#cwg299-ushort {{conversion to integral type 'unsigned short' declared here}}
1306 // since-cxx14-error-re@#cwg299-q {{{{conversion from 'T' to 'unsigned (long long|long|int)' is ambiguous}}}}
1307 // since-cxx14-note@#cwg299-int {{candidate function}}
1308 // since-cxx14-note@#cwg299-ushort {{candidate function}}
1309 }