Debian Codegraph @

clang/test/CXX/drs/cwg4xx.cpp

raw
1 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98-17,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify=expected,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify=expected,cxx98-14,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17,cxx98-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++20 %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++23 %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++2c %s -verify=expected,since-cxx20,since-cxx17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
8
9 #if __cplusplus == 199711L
10 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
11 // cxx98-error@-1 {{variadic macros are a C99 feature}}
12 #endif
13
14 // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
15 __extension__ typedef __SIZE_TYPE__ size_t;
16
17 namespace std { struct type_info; }
18
19 namespace cwg400 { // cwg400: yes
20 struct A { int a; struct a {}; }; // #cwg400-A
21 struct B { int a; struct a {}; }; // #cwg400-B
22 struct C : A, B { using A::a; struct a b; };
23 struct D : A, B {
24 using A::a;
25 // FIXME: we should issue a single diagnostic
26 using B::a; // #cwg400-using-B-a
27 // expected-error@#cwg400-using-B-a {{target of using declaration conflicts with declaration already in scope}}
28 // expected-note@#cwg400-B {{target of using declaration}}
29 // expected-note@#cwg400-A {{conflicting declaration}}
30 // expected-error@#cwg400-using-B-a {{target of using declaration conflicts with declaration already in scope}}
31 // expected-note@#cwg400-B {{target of using declaration}}
32 // expected-note@#cwg400-A {{conflicting declaration}}
33 struct a b;
34 };
35 struct E : A, B { struct a b; };
36 // expected-error@-1 {{member 'a' found in multiple base classes of different types}}
37 // expected-note@#cwg400-A {{member type 'cwg400::A::a' found by ambiguous name lookup}}
38 // expected-note@#cwg400-B {{member type 'cwg400::B::a' found by ambiguous name lookup}}
39 }
40
41 namespace cwg401 { // cwg401: 2.8
42 template<class T, class U = typename T::type> class A : public T {}; // #cwg401-A
43 // expected-error@#cwg401-A {{'type' is a private member of 'cwg401::C'}}
44 // expected-note@#cwg402-friend-A-C {{in instantiation of default argument for 'A<C>' required here}}
45 // expected-note@#cwg402-C-type {{implicitly declared private here}}
46 // expected-error@#cwg401-A {{'type' is a protected member of 'cwg401::B'}}
47 // expected-note@#cwg402-b {{in instantiation of default argument for 'A<B>' required here}}
48 // expected-note@#cwg402-B-type {{declared protected here}}
49 // expected-error@#cwg401-A {{'type' is a private member of 'cwg401::D'}}
50 // expected-note@#cwg402-d {{in instantiation of default argument for 'A<D>' required here}}
51 // expected-note@#cwg402-D-type {{implicitly declared private here}}
52 class B {
53 protected:
54 typedef int type; // #cwg402-B-type
55 };
56
57 class C {
58 typedef int type; // #cwg402-C-type
59 friend class A<C>; // #cwg402-friend-A-C
60 };
61
62 class D {
63 typedef int type; // #cwg402-D-type
64 friend class A<D, int>;
65 };
66
67 A<B> *b; // #cwg402-b
68 A<D> *d; // #cwg402-d
69
70 struct E {
71 template<class T, class U = typename T::type> class A : public T {};
72 };
73 class F {
74 typedef int type;
75 friend class E;
76 };
77 E::A<F> eaf; // ok, default argument is in befriended context
78
79 // FIXME: Why do we get different diagnostics in C++11 onwards here? We seem
80 // to not treat the default template argument as a SFINAE context in C++98.
81 template<class T, class U = typename T::type> void f(T) {} // #cwg402-f
82 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
83 // cxx98-error@-2 {{'type' is a protected member of 'cwg401::B'}}
84 // cxx98-note@-3 {{in instantiation of default argument for 'f<B>' required here}}
85 // cxx98-note@#cwg402-f-b {{while substituting deduced template arguments into function template 'f' [with T = B, U = (no value)]}}
86 // cxx98-note@#cwg402-B-type {{declared protected here}}
87 void g(B b) { f(b); } // #cwg402-f-b
88 // since-cxx11-error@-1 {{no matching function for call to 'f'}}
89 // since-cxx11-note@#cwg402-f {{candidate template ignored: substitution failure [with T = B, U = typename B::type]: 'type' is a protected member of 'cwg401::B'}}
90 }
91
92 namespace cwg403 { // cwg403: yes
93 namespace A {
94 struct S {};
95 int f(void*);
96 }
97 template<typename T> struct X {};
98 typedef struct X<A::S>::X XS;
99 XS *p;
100 int k = f(p); // ok, finds A::f, even though type XS is a typedef-name
101 // referring to an elaborated-type-specifier naming a
102 // injected-class-name, which is about as far from a
103 // template-id as we can make it.
104 }
105
106 // cwg404: na
107 // (NB: also sup 594)
108
109 namespace cwg405 { // cwg405: yes
110 // NB: also dup 218
111 namespace A {
112 struct S {};
113 void f(S);
114 }
115 namespace B {
116 struct S {};
117 void f(S);
118 }
119
120 struct C {
121 int f;
122 void test1(A::S as) { f(as); }
123 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
124 void test2(A::S as) { void f(); f(as); }
125 // expected-error@-1 {{too many arguments to function call, expected 0, have 1}}
126 // expected-note@-2 {{'f' declared here}}
127 void test3(A::S as) { using A::f; f(as); } // ok
128 void test4(A::S as) { using B::f; f(as); } // ok
129 void test5(A::S as) { int f; f(as); }
130 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
131 void test6(A::S as) { struct f {}; (void) f(as); }
132 // expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}}
133 // expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}}
134 // since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}}
135 // expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
136 };
137
138 namespace D {
139 struct S {};
140 struct X { void operator()(S); } f;
141 }
142 void testD(D::S ds) { f(ds); }
143 // expected-error@-1 {{use of undeclared identifier 'f'}}
144
145 namespace E {
146 struct S {};
147 struct f { f(S); };
148 }
149 void testE(E::S es) { f(es); }
150 // expected-error@-1 {{use of undeclared identifier 'f'}}
151 }
152
153 namespace cwg406 { // cwg406: 2.9
154 typedef struct {
155 static int n;
156 // expected-error@-1 {{static data member 'n' not allowed in anonymous struct}}
157 } A;
158 typedef union {
159 static int n;
160 // expected-error@-1 {{static data member 'n' not allowed in anonymous union}}
161 } B;
162 }
163
164 namespace cwg407 { // cwg407: 3.8
165 // NB: reused by cwg1894 and cwg2199
166 struct S;
167 typedef struct S S;
168 void f() {
169 struct S *p;
170 {
171 typedef struct S S; // #cwg407-typedef-S
172 struct S *p;
173 // expected-error@-1 {{typedef 'S' cannot be referenced with the 'struct' specifier}}
174 // expected-note@#cwg407-typedef-S {{declared here}}
175 }
176 }
177 struct S {};
178
179 namespace UsingDir {
180 namespace A {
181 struct S {}; // #cwg407-A-S
182 }
183 namespace B {
184 typedef int S; // #cwg407-B-S
185 }
186 namespace C {
187 using namespace A;
188 using namespace B;
189 struct S s;
190 // expected-error@-1 {{ambiguous}}
191 // expected-note@#cwg407-A-S {{candidate found by name lookup is 'cwg407::UsingDir::A::S'}}
192 // expected-note@#cwg407-B-S {{candidate found by name lookup is 'cwg407::UsingDir::B::S'}}
193 }
194 namespace D {
195 using A::S;
196 typedef struct S S;
197 struct S s;
198 }
199 namespace E {
200 // The standard doesn't say whether this is valid. We interpret
201 // CWG407 as meaning "if lookup finds both a tag and a typedef with the
202 // same type, then it's OK in an elaborated-type-specifier".
203 typedef A::S S;
204 using A::S;
205 struct S s;
206 }
207 namespace F {
208 typedef A::S S;
209 }
210 // The standard doesn't say what to do in these cases either.
211 namespace G {
212 using namespace A;
213 using namespace F;
214 struct S s;
215 }
216 namespace H {
217 using namespace F;
218 using namespace A;
219 struct S s;
220 }
221 }
222 }
223
224 namespace cwg408 { // cwg408: 3.4
225 template<int N> void g() { static_assert(N != 1, ""); }
226 template<> void g<2>() { }
227
228 template<typename T> struct S {
229 static int i[];
230 void f();
231 };
232 template<typename T> int S<T>::i[] = { 1 };
233
234 template<typename T> void S<T>::f() {
235 g<sizeof (i) / sizeof (int)>();
236 }
237 template<> int S<int>::i[] = { 1, 2 };
238 template void S<int>::f(); // uses g<2>(), not g<1>().
239
240
241 template<typename T> struct R {
242 static int arr[];
243 void f();
244 };
245 template<typename T> int R<T>::arr[1];
246 template<typename T> void R<T>::f() {
247 static_assert(sizeof(arr) != sizeof(int), "");
248 }
249 template<> int R<int>::arr[2];
250 template void R<int>::f();
251 }
252
253 namespace cwg409 { // cwg409: yes
254 template<typename T> struct A {
255 typedef int B;
256 B b1;
257 A::B b2;
258 A<T>::B b3;
259 A<T*>::B b4;
260 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::B; implicit 'typename' is a C++20 extension}}
261 };
262 }
263
264 namespace cwg410 { // cwg410: no
265 template<class T> void f(T);
266 void g(int);
267 namespace M {
268 template<class T> void h(T);
269 template<class T> void i(T);
270 struct A {
271 friend void f<>(int);
272 friend void h<>(int);
273 friend void g(int);
274 template<class T> void i(T);
275 friend void i<>(int);
276 private:
277 static void z(); // #cwg410-z
278 };
279
280 template<> void h(int) { A::z(); }
281 // FIXME: This should be ill-formed. The member A::i<> is befriended,
282 // not this function.
283 template<> void i(int) { A::z(); }
284 }
285 template<> void f(int) { M::A::z(); }
286 void g(int) { M::A::z(); }
287 // expected-error@-1 {{'z' is a private member of 'cwg410::M::A'}}
288 // expected-note@#cwg410-z {{declared private here}}
289 }
290
291 // cwg412 is in cwg412.cpp
292
293 namespace cwg413 { // cwg413: yes
294 struct S {
295 int a;
296 int : 17;
297 int b;
298 };
299 S s = { 1, 2, 3 };
300 // expected-error@-1 {{excess elements in struct initializer}}
301
302 struct E {};
303 struct T { // #cwg413-T
304 int a;
305 E e;
306 int b;
307 };
308 T t1 = { 1, {}, 2 };
309 T t2 = { 1, 2 };
310 // expected-error@-1 {{initializer for aggregate with no elements requires explicit braces}}
311 // expected-note@#cwg413-T {{'cwg413::T' declared here}}
312 }
313
314 namespace cwg414 { // cwg414: dup 305
315 struct X {};
316 void f() {
317 X x;
318 struct X {};
319 x.~X();
320 }
321 }
322
323 namespace cwg415 { // cwg415: yes
324 template<typename T> void f(T, ...) { T::error; }
325 void f(int, int);
326 void g() { f(0, 0); } // ok
327 }
328
329 namespace cwg416 { // cwg416: yes
330 extern struct A a;
331 int &operator+(const A&, const A&);
332 int &k = a + a;
333 struct A { float &operator+(A&); };
334 float &f = a + a;
335 }
336
337 namespace cwg417 { // cwg417: no
338 struct A;
339 struct cwg417::A {};
340 // expected-warning@-1 {{extra qualification on member 'A'}}
341 struct B { struct X; };
342 struct C : B {};
343 struct C::X {};
344 // expected-error@-1 {{no struct named 'X' in 'cwg417::C'}}
345 struct B::X { struct Y; };
346 struct C::X::Y {}; // ok!
347 namespace N {
348 struct D;
349 struct E;
350 struct F;
351 struct H;
352 }
353 // FIXME: This is ill-formed.
354 using N::D;
355 struct cwg417::D {};
356 // expected-warning@-1 {{extra qualification on member 'D'}}
357 using namespace N;
358 struct cwg417::E {};
359 // expected-error@-1 {{no struct named 'E' in namespace 'cwg417'}}
360 // expected-warning@-2 {{extra qualification on member 'E'}}
361 struct N::F {};
362 struct G;
363 using N::H;
364 namespace M {
365 struct cwg417::G {};
366 // expected-error@-1 {{cannot define or redeclare 'G' here because namespace 'M' does not enclose namespace 'cwg417'}}
367 struct cwg417::H {};
368 // expected-error@-1 {{cannot define or redeclare 'H' here because namespace 'M' does not enclose namespace 'cwg417'}}
369 }
370 }
371
372 namespace cwg418 { // cwg418: no
373 namespace example1 {
374 void f1(int, int = 0);
375 void f1(int = 0, int);
376
377 void g() { f1(); }
378 } // namespace example1
379
380 namespace example2 {
381 namespace A {
382 void f2(int); // #cwg418-f2
383 }
384 namespace B {
385 using A::f2;
386 }
387 namespace A {
388 void f2(int = 3);
389 }
390 void g2() {
391 using B::f2;
392 f2();
393 // expected-error@-1 {{no matching function for call to 'f2'}}
394 // expected-note@#cwg418-f2 {{candidate function not viable: requires 1 argument, but 0 were provided}}
395 }
396 } // namespace example2
397
398 // example from [over.match.best]/4
399 namespace example3 {
400 namespace A {
401 extern "C" void f(int = 5);
402 }
403 namespace B {
404 extern "C" void f(int = 5);
405 }
406
407 using A::f;
408 using B::f;
409
410 void use() {
411 f(3);
412 f(); // FIXME: this should fail
413 }
414 } // namespace example3
415 } // namespace cwg418
416
417 namespace cwg420 { // cwg420: 9
418 template<typename T> struct ptr {
419 T *operator->() const;
420 T &operator*() const;
421 };
422 template<typename T, typename P> void test(P p) {
423 p->~T();
424 p->T::~T();
425 (*p).~T();
426 (*p).T::~T();
427 }
428 struct X {};
429 template void test<int>(int*);
430 template void test<int>(ptr<int>);
431 template void test<X>(X*);
432 template void test<X>(ptr<X>);
433
434 template<typename T>
435 void test2(T p) {
436 p->template Y<int>::~Y<int>();
437 p->~Y<int>();
438 p->template ~Y<int>();
439 // expected-error@-1 {{'template' keyword not permitted in destructor name}}
440 }
441 template<typename T> struct Y {};
442 template void test2(Y<int>*);
443 template void test2(ptr<Y<int> >);
444
445 void test3(int *p, ptr<int> q) {
446 typedef int Int;
447 p->~Int();
448 q->~Int();
449 p->Int::~Int();
450 q->Int::~Int();
451 }
452
453 #if __cplusplus >= 201103L
454 template<typename T> using id = T;
455 struct A { template<typename T> using id = T; };
456 void test4(int *p, ptr<int> q) {
457 p->~id<int>();
458 q->~id<int>();
459 p->id<int>::~id<int>();
460 q->id<int>::~id<int>();
461 p->template id<int>::~id<int>(); // OK since cwg2292
462 q->template id<int>::~id<int>(); // OK since cwg2292
463 p->A::template id<int>::~id<int>();
464 q->A::template id<int>::~id<int>();
465 }
466 #endif
467 }
468
469 namespace cwg421 { // cwg421: yes
470 struct X { X(); int n; int &r; };
471 int *p = &X().n;
472 // cxx98-error@-1 {{taking the address of a temporary object of type 'int'}}
473 // since-cxx11-error@-2 {{cannot take the address of an rvalue of type 'int'}}
474 int *q = &X().r;
475 }
476
477 namespace cwg422 { // cwg422: yes
478 template<typename T, typename U> void f() {
479 typedef T type; // #cwg422-typedef-T
480 typedef U type;
481 // expected-error@-1 {{typedef redefinition with different types ('char' vs 'int')}}
482 // expected-note@#cwg422-f-int-char {{in instantiation of function template specialization 'cwg422::f<int, char>' requested here}}
483 // expected-note@#cwg422-typedef-T {{previous definition is here}}
484 }
485 template void f<int, int>();
486 template void f<int, char>(); // #cwg422-f-int-char
487 }
488
489 namespace cwg423 { // cwg423: yes
490 template<typename T> struct X { operator T&(); };
491 void f(X<int> x) { x += 1; }
492 }
493
494 namespace cwg424 { // cwg424: yes
495 struct A {
496 typedef int N; // #cwg424-N
497 typedef int N;
498 // expected-error@-1 {{redefinition of 'N'}}
499 // expected-note@#cwg424-N {{previous definition is here}}
500
501 struct X;
502 typedef X X; // #cwg424-X
503 struct X {};
504
505 struct X *p;
506 struct A::X *q;
507 X *r;
508
509 typedef X X;
510 // expected-error@-1 {{redefinition of 'X'}}
511 // expected-note@#cwg424-X {{previous definition is here}}
512 };
513 struct B {
514 typedef int M;
515 };
516 struct C : B {
517 typedef int M; // #cwg424-M
518 typedef int M;
519 // expected-error@-1 {{redefinition of 'M'}}
520 // expected-note@#cwg424-M {{previous definition is here}}
521 };
522 }
523
524 namespace cwg425 { // cwg425: yes
525 struct A { template<typename T> operator T() const; } a;
526 float f = 1.0f * a;
527 // expected-error@-1 {{use of overloaded operator '*' is ambiguous (with operand types 'float' and 'struct A')}}
528 // expected-note@-2 +{{built-in candidate}}
529
530 template<typename T> struct is_float;
531 template<> struct is_float<float> { typedef void type; };
532
533 struct B {
534 template<typename T, typename U = typename is_float<T>::type> operator T() const;
535 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
536 } b;
537 float g = 1.0f * b; // ok
538 }
539
540 namespace cwg427 { // cwg427: yes
541 struct B {};
542 struct D : public B {
543 D(B &) = delete; // #cwg427-D
544 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
545 };
546
547 extern D d1;
548 B &b = d1;
549 const D &d2 = static_cast<const D&>(b);
550 const D &d3 = (const D&)b;
551 const D &d4(b);
552 // expected-error@-1 {{conversion function from 'B' to 'const D' invokes a deleted function}}
553 // expected-note@#cwg427-D {{'D' has been explicitly marked deleted here}}
554 }
555
556 namespace cwg428 { // cwg428: yes
557 template<typename T> T make();
558 extern struct X x; // #cwg428-X
559 void f() {
560 throw void();
561 // expected-error@-1 {{cannot throw}}
562 throw make<void*>();
563 throw make<const volatile void*>();
564 throw x;
565 // expected-error@-1 {{cannot throw}}
566 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
567 throw make<X&>();
568 // expected-error@-1 {{cannot throw}}
569 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
570 throw make<X*>();
571 // expected-error@-1 {{cannot throw}}
572 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
573 throw make<const volatile X&>();
574 // expected-error@-1 {{cannot throw}}
575 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
576 throw make<const volatile X*>();
577 // expected-error@-1 {{cannot throw}}
578 // expected-note@#cwg428-X {{forward declaration of 'cwg428::X'}}
579 }
580 }
581
582 namespace cwg429 { // cwg429: 2.8 c++11
583 // FIXME: This rule is obviously intended to apply to C++98 as well.
584 struct A {
585 static void *operator new(size_t, size_t);
586 static void operator delete(void*, size_t); // #cwg429-delete
587 } *a = new (0) A;
588 // since-cxx11-error@-1 {{'new' expression with placement arguments refers to non-placement 'operator delete'}}
589 // since-cxx11-note@#cwg429-delete {{here}}
590 struct B {
591 static void *operator new(size_t, size_t);
592 static void operator delete(void*);
593 static void operator delete(void*, size_t);
594 } *b = new (0) B; // ok, second delete is not a non-placement deallocation function
595 }
596
597 namespace cwg430 { // cwg430: yes c++11
598 // resolved by n2239
599 // FIXME: This should apply in C++98 too.
600 void f(int n) {
601 int a[] = { n++, n++, n++ };
602 // cxx98-warning@-1 {{multiple unsequenced modifications to 'n'}}
603 }
604 }
605
606 namespace cwg431 { // cwg431: yes
607 struct A {
608 template<typename T> T *get();
609 template<typename T> struct B {
610 template<typename U> U *get();
611 };
612 };
613
614 template<typename T> void f(A a) {
615 a.get<A>()->get<T>();
616 a.get<T>()
617 ->get<T>();
618 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
619 a.get<T>()->template get<T>();
620 a.A::get<T>();
621 A::B<int> *b = a.get<A::B<int> >();
622 b->get<int>();
623 b->A::B<int>::get<int>();
624 b->A::B<int>::get<T>();
625 b->A::B<T>::get<int>();
626 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
627 b->A::B<T>::template get<int>();
628 b->A::B<T>::get<T>();
629 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
630 b->A::B<T>::template get<T>();
631 A::B<T> *c = a.get<A::B<T> >();
632 c->get<int>();
633 // expected-error@-1 {{use 'template' keyword to treat 'get' as a dependent template name}}
634 c->template get<int>();
635 }
636 }
637
638 namespace cwg432 { // cwg432: 3.0
639 template<typename T> struct A {};
640 template<typename T> struct B : A<B> {};
641 // expected-error@-1 {{use of class template 'B' requires template arguments}}
642 // expected-note@-2 {{template is declared here}}
643 template<typename T> struct C : A<C<T> > {};
644 #if __cplusplus >= 201103L
645 template<typename T> struct D : decltype(A<D>()) {};
646 // since-cxx11-error@-1 {{use of class template 'D' requires template arguments}}
647 // since-cxx11-note@-2 {{template is declared here}}
648 #endif
649 }
650
651 namespace cwg433 { // cwg433: yes
652 template<class T> struct S {
653 void f(union U*);
654 };
655 U *p;
656 template<class T> void S<T>::f(union U*) {}
657
658 S<int> s;
659 }
660
661 namespace cwg434 { // cwg434: sup 2352
662 void f() {
663 const int ci = 0;
664 int *pi = 0;
665 const int *&rpci = pi;
666 // expected-error@-1 {{binding reference of type 'const int *' to value of type 'int *' not permitted due to incompatible qualifiers}}
667 const int * const &rcpci = pi; // OK
668 rpci = &ci;
669 *pi = 1;
670 }
671
672 #if __cplusplus >= 201103L
673 int *pi = 0;
674 const int * const &rcpci = pi;
675 static_assert(&rcpci == &pi, "");
676 #endif
677 }
678
679 // cwg435: na
680
681 namespace cwg436 { // cwg436: yes
682 enum E { f }; // #cwg436-f
683 void f();
684 // expected-error@-1 {{redefinition of 'f' as different kind of symbol}}
685 // expected-note@#cwg436-f {{previous definition is here}}
686 }
687
688 namespace cwg437 { // cwg437: sup 1308
689 // This is superseded by 1308, which is in turn superseded by 1330,
690 // which restores this rule.
691 template<typename U> struct T : U {};
692 struct S {
693 void f() throw(S);
694 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
695 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
696 void g() throw(T<S>);
697 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
698 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
699 struct U;
700 void h() throw(U);
701 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
702 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
703 struct U {};
704 };
705 }
706
707 // cwg438 is in cwg438.cpp
708 // cwg439 is in cwg439.cpp
709 // cwg441 is in cwg441.cpp
710 // cwg442: sup 348
711 // cwg443: na
712
713 namespace cwg444 { // cwg444: yes
714 struct D;
715 struct B { // #cwg444-B
716 D &operator=(D &) = delete; // #cwg444-deleted
717 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
718 };
719 struct D : B { // #cwg444-D
720 using B::operator=;
721 } extern d;
722 void f() {
723 d = d;
724 // expected-error@-1 {{overload resolution selected deleted operator '='}}
725 // expected-note@#cwg444-deleted {{candidate function has been explicitly deleted}}
726 // expected-note@#cwg444-D {{candidate function (the implicit copy assignment operator)}}
727 // expected-note@#cwg444-B {{candidate function (the implicit copy assignment operator)}}
728 // since-cxx11-note@#cwg444-B {{candidate function (the implicit move assignment operator) not viable: expects an rvalue for 1st argument}}
729 // since-cxx11-note@#cwg444-D {{candidate function (the implicit move assignment operator) not viable: expects an rvalue for 1st argument}}
730 }
731 }
732
733 namespace cwg445 { // cwg445: 3.2
734 class A { void f(); }; // #cwg445-f
735 struct B {
736 friend void A::f();
737 // expected-error@-1 {{friend function 'f' is a private member of 'cwg445::A'}}
738 // expected-note@#cwg445-f {{implicitly declared private here}}
739 };
740 }
741
742 namespace cwg446 { // cwg446: 2.8
743 struct C;
744 struct A {
745 A();
746 A(const A&) = delete; // #cwg446-deleted
747 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
748 A(const C&);
749 };
750 struct C : A {};
751 void f(A a, bool b, C c) {
752 void(b ? a : a);
753 b ? A() : a;
754 // expected-error@-1 {{call to deleted constructor of 'A'}}
755 // expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
756 b ? a : A();
757 // expected-error@-1 {{call to deleted constructor of 'A'}}
758 // expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
759 b ? A() : A();
760 // cxx98-14-error@-1 {{call to deleted constructor of 'A'}}
761 // expected-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
762
763 void(b ? a : c);
764 b ? a : C();
765 // expected-error@-1 {{call to deleted constructor of 'A'}}
766 // cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
767 b ? c : A();
768 // cxx98-14-error@-1 {{call to deleted constructor of 'A'}}
769 // cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
770 b ? A() : C();
771 // cxx98-14-error@-1 {{call to deleted constructor of 'A'}}
772 // cxx98-14-note@#cwg446-deleted {{'A' has been explicitly marked deleted here}}
773 }
774 }
775
776 namespace cwg447 { // cwg447: yes
777 struct A { int n; int a[4]; };
778 template<int> struct U {
779 typedef int type;
780 template<typename V> static void h();
781 };
782 template<typename T> U<sizeof(T)> g(T);
783 template<typename T, int N> void f(int n) {
784 // ok, not type dependent
785 g(__builtin_offsetof(A, n)).h<int>();
786 g(__builtin_offsetof(T, n)).h<int>();
787 // value dependent if first argument is a dependent type
788 U<__builtin_offsetof(A, n)>::type a;
789 // FIXME: instead of ";", we should be suggesting "typename"
790 U<__builtin_offsetof(T, n)>::type b;
791 // expected-error@-1 {{expected ';' after expression}}
792 // expected-error@-2 {{use of undeclared identifier 'b'}}
793 // as an extension, we allow the member-designator to include array indices
794 g(__builtin_offsetof(A, a[0])).h<int>();
795 g(__builtin_offsetof(A, a[N])).h<int>();
796 U<__builtin_offsetof(A, a[0])>::type c;
797 // FIXME: instead of ";", we should be suggesting "typename"
798 U<__builtin_offsetof(A, a[N])>::type d;
799 // expected-error@-1 {{expected ';' after expression}}
800 // expected-error@-2 {{use of undeclared identifier 'd'}}
801 }
802 }
803
804 namespace cwg448 { // cwg448: 2.8
805 template<typename T = int> void f(int); // #cwg448-f-int
806 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
807 template<typename T> void g(T t) {
808 f<T>(t);
809 // expected-error@-1 {{call to function 'f' that is neither visible in the template definition nor found by argument-dependent lookup}}
810 // expected-note@#cwg448-g {{in instantiation of function template specialization 'cwg448::g<cwg448::HideFromADL::X>' requested here}}
811 // expected-note@#cwg448-f-T {{'f' should be declared prior to the call site or in namespace 'cwg448::HideFromADL'}}
812 cwg448::f(t);
813 // expected-error@-1 {{no matching function for call to 'f'}}
814 // expected-note@#cwg448-f-int {{candidate function template not viable: no known conversion from 'cwg448::HideFromADL::X' to 'int' for 1st argument}}
815 }
816 template<typename T> void f(T); // #cwg448-f-T
817 namespace HideFromADL { struct X {}; }
818 template void g(int); // ok
819 template void g(HideFromADL::X); // #cwg448-g
820 }
821
822 // cwg449: na
823
824 namespace cwg450 { // cwg450: yes
825 typedef int A[3];
826 void f1(const A &);
827 void f2(A &); // #cwg450-f2
828 struct S { A n; };
829 void g() {
830 f1(S().n);
831 f2(S().n);
832 // expected-error@-1 {{no matching function for call to 'f2'}}}
833 // expected-note@#cwg450-f2 {{candidate function not viable: expects an lvalue for 1st argument}}
834 }
835 #if __cplusplus >= 201103L
836 void h() {
837 f1(A{});
838 f2(A{});
839 // expected-error@-1 {{no matching function for call to 'f2'}}}
840 // expected-note@#cwg450-f2 {{candidate function not viable: expects an lvalue for 1st argument}}
841 }
842 #endif
843 }
844
845 namespace cwg451 { // cwg451: yes
846 const int a = 1 / 0;
847 // expected-warning@-1 {{division by zero is undefined}}
848 const int b = 1 / 0; // #cwg451-b
849 // expected-warning@-1 {{division by zero is undefined}}
850 static_assert(b, "");
851 // expected-error@-1 {{expression is not an integral constant expression}}
852 // expected-note@-2 {{initializer of 'b' is not a constant expression}}
853 // expected-note@#cwg451-b {{declared here}}
854 }
855
856 namespace cwg452 { // cwg452: yes
857 struct A {
858 int a, b, c;
859 A *p;
860 int f();
861 A() : a(f()), b(this->f() + a), c(this->a), p(this) {}
862 };
863 }
864
865 // cwg454 FIXME write a codegen test
866
867 namespace cwg456 { // cwg456: yes
868 // sup 903 c++11
869 const int null = 0;
870 void *p = null;
871 // cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}
872 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an lvalue of type 'const int'}}
873
874 const bool f = false;
875 void *q = f;
876 // cxx98-warning@-1 {{initialization of pointer of type 'void *' to null from a constant boolean}}
877 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an lvalue of type 'const bool'}}
878 }
879
880 namespace cwg457 { // cwg457: yes
881 const int a = 1;
882 const volatile int b = 1;
883 static_assert(a, "");
884 static_assert(b, "");
885 // expected-error@-1 {{expression is not an integral constant expression}}
886 // expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}
887
888 enum E {
889 ea = a,
890 eb = b
891 // expected-error@-1 {{expression is not an integral constant expression}}
892 // expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}
893 };
894 }
895
896 namespace cwg458 { // cwg458: 11
897 struct A {
898 int T;
899 int f();
900 template<typename> int g();
901 };
902
903 template<typename> struct B : A {
904 int f();
905 template<typename> int g();
906 template<typename> int h();
907 };
908
909 int A::f() {
910 return T;
911 }
912 template<typename T> // #cwg458-g-T
913 int A::g() {
914 return T;
915 // expected-error@-1 {{'T' does not refer to a value}}
916 // expected-note@#cwg458-g-T {{declared here}}
917 }
918
919 template<typename T>
920 int B<T>::f() {
921 return T;
922 }
923 template<typename T>
924 template<typename U>
925 int B<T>::g() {
926 return T;
927 }
928 template<typename U>
929 template<typename T> // #cwg458-h-T
930 int B<U>::h() {
931 return T;
932 // expected-error@-1 {{'T' does not refer to a value}}
933 // expected-note@#cwg458-h-T {{declared here}}
934 }
935 }
936
937 namespace cwg460 { // cwg460: yes
938 namespace X { namespace Q { int n; } }
939 namespace Y {
940 using X;
941 // expected-error@-1 {{using declaration requires a qualified name}}
942 using cwg460::X;
943 // expected-error@-1 {{using declaration cannot refer to a namespace}}
944 // expected-note@-2 {{did you mean 'using namespace'?}}
945 using X::Q;
946 // expected-error@-1 {{using declaration cannot refer to a namespace}}
947 // expected-note@-2 {{did you mean 'using namespace'?}}
948 }
949 }
950
951 // cwg461: na
952 // cwg462 is in cwg462.cpp
953 // cwg463: na
954 // cwg464: na
955 // cwg465: na
956
957 namespace cwg466 { // cwg466: 2.8
958 typedef int I;
959 typedef const int CI;
960 typedef volatile int VI;
961 void g(int a, CI b, VI c) {
962 // since-cxx20-warning@-1 {{volatile-qualified parameter type 'VI' (aka 'volatile int') is deprecated}}
963 a.~I();
964 a.~CI();
965 a.~VI();
966 a.I::~I();
967 a.CI::~CI();
968 a.VI::~VI();
969
970 a.CI::~VI(); // allowed by changes to [expr.id.prim.qual]/2 introduced in P1131R2
971
972 b.~I();
973 b.~CI();
974 b.~VI();
975 b.I::~I();
976 b.CI::~CI();
977 b.VI::~VI();
978
979 c.~I();
980 c.~CI();
981 c.~VI();
982 c.I::~I();
983 c.CI::~CI();
984 c.VI::~VI();
985 }
986 }
987
988 namespace cwg467 { // cwg467: yes
989 int stuff();
990
991 int f() {
992 static bool done;
993 if (done)
994 goto later;
995 static int k = stuff();
996 done = true;
997 later:
998 return k;
999 }
1000 int g() {
1001 goto later;
1002 // expected-error@-1 {{cannot jump from this goto statement to its label}}
1003 // expected-note@#cwg467-k {{jump bypasses variable initialization}}
1004 int k = stuff(); // #cwg467-k
1005 later:
1006 return k;
1007 }
1008 }
1009
1010 namespace cwg468 { // cwg468: yes c++11
1011 // FIXME: Should we allow this in C++98 too?
1012 template<typename> struct A {
1013 template<typename> struct B {
1014 static int C;
1015 };
1016 };
1017 int k = cwg468::template A<int>::template B<char>::C;
1018 // cxx98-error@-1 {{'template' keyword outside of a template}}
1019 // cxx98-error@-2 {{'template' keyword outside of a template}}
1020 }
1021
1022 namespace cwg469 { // cwg469: no
1023 template<typename T> struct X; // #cwg469-X
1024 template<typename T> struct X<const T> {};
1025 X<int&> x;
1026 // expected-error@-1 {{implicit instantiation of undefined template 'cwg469::X<int &>'}}
1027 // expected-note@#cwg469-X {{template is declared here}}
1028 }
1029
1030 namespace cwg470 { // cwg470: yes
1031 template<typename T> struct A {
1032 struct B {};
1033 };
1034 template<typename T> struct C {
1035 };
1036
1037 template struct A<int>; // #cwg470-A-int
1038 template struct A<int>::B;
1039 // expected-error@-1 {{duplicate explicit instantiation of 'B'}}
1040 // expected-note@#cwg470-A-int {{previous explicit instantiation is here}}
1041
1042 // ok, instantiating C<char> doesn't instantiate base class members.
1043 template struct A<char>;
1044 template struct C<char>;
1045 }
1046
1047 namespace cwg471 { // cwg471: 2.8
1048 struct A { int n; };
1049 struct B : private virtual A {};
1050 struct C : protected virtual A {};
1051 struct D : B, C { int f() { return n; } };
1052 struct E : private virtual A {
1053 using A::n;
1054 };
1055 struct F : E, B { int f() { return n; } };
1056 struct G : virtual A {
1057 private:
1058 using A::n; // #cwg471-G-using
1059 };
1060 struct H : B, G { int f() { return n; } };
1061 // expected-error@-1 {{'n' is a private member of 'cwg471::G'}}
1062 // expected-note@#cwg471-G-using {{declared private here}}
1063 }
1064
1065 namespace cwg472 { // cwg472: no drafting 2011-04
1066 struct B {
1067 int i; // #cwg472-i
1068 };
1069 struct I : protected B {}; // #cwg472-struct-I
1070 struct D : public I {
1071 void f(I *ip) {
1072 ip->i = 0;
1073 // expected-error@-1 {{'i' is a protected member of 'cwg472::B'}}
1074 // expected-note@#cwg472-struct-I {{constrained by protected inheritance here}}
1075 // expected-note@#cwg472-i {{member is declared here}}
1076 B *bp = ip;
1077 bp->i = 5;
1078 }
1079 };
1080 }
1081
1082 namespace cwg474 { // cwg474: 3.4
1083 namespace N {
1084 struct S {
1085 void f();
1086 };
1087 }
1088 void N::S::f() {
1089 void g(); // #cwg474-g
1090 }
1091 int g();
1092 namespace N {
1093 int g();
1094 // expected-error@-1 {{functions that differ only in their return type cannot be overloaded}}
1095 // expected-note@#cwg474-g {{previous declaration is here}}
1096 }
1097 }
1098
1099 // cwg475 FIXME write a libc++abi test
1100
1101 namespace cwg477 { // cwg477: 3.5
1102 struct A {
1103 explicit A();
1104 virtual void f();
1105 };
1106 struct B {
1107 friend explicit A::A();
1108 // expected-error@-1 {{'explicit' is invalid in friend declarations}}
1109 friend virtual void A::f();
1110 // expected-error@-1 {{'virtual' is invalid in friend declarations}}
1111 };
1112 explicit A::A() {}
1113 // expected-error@-1 {{can only be specified inside the class definition}}
1114 virtual void A::f() {}
1115 // expected-error@-1 {{can only be specified inside the class definition}}
1116 }
1117
1118 namespace cwg478 { // cwg478: yes
1119 struct A { virtual void f() = 0; }; // #cwg478-f
1120 void f(A *a);
1121 void f(A a[10]);
1122 // expected-error@-1 {{array of abstract class type 'A'}}
1123 // expected-note@#cwg478-f {{unimplemented pure virtual method 'f' in 'A'}}
1124 }
1125
1126 namespace cwg479 { // cwg479: 2.8
1127 struct S {
1128 S();
1129 private:
1130 S(const S&); // #cwg479-S-copy-ctor
1131 ~S(); // #cwg479-S-dtor
1132 };
1133 void f() {
1134 throw S();
1135 // expected-error@-1 {{temporary of type 'S' has private destructor}}
1136 // expected-note@#cwg479-S-dtor {{declared private here}}
1137 // expected-error@-3 {{exception object of type 'S' has private destructor}}
1138 // expected-note@#cwg479-S-dtor {{declared private here}}
1139 // cxx98-error@-5 {{C++98 requires an accessible copy constructor for class 'cwg479::S' when binding a reference to a temporary; was private}}
1140 // cxx98-note@#cwg479-S-copy-ctor {{declared private here}}
1141 // cxx98-14-error@-7 {{calling a private constructor of class 'cwg479::S'}}
1142 // cxx98-14-note@#cwg479-S-copy-ctor {{declared private here}}
1143 }
1144 void g() {
1145 S s;
1146 // expected-error@-1 {{variable of type 'S' has private destructor}}
1147 // expected-note@#cwg479-S-dtor {{declared private here}}
1148 throw s;
1149 // expected-error@-1 {{exception object of type 'S' has private destructor}}
1150 // expected-note@#cwg479-S-dtor {{declared private here}}
1151 // expected-error@-3 {{calling a private constructor of class 'cwg479::S'}}
1152 // expected-note@#cwg479-S-copy-ctor {{declared private here}}
1153 }
1154 void h() {
1155 try {
1156 f();
1157 g();
1158 } catch (S s) {
1159 // expected-error@-1 {{calling a private constructor of class 'cwg479::S'}}
1160 // expected-note@#cwg479-S-copy-ctor {{declared private here}}
1161 // expected-error@-3 {{variable of type 'S' has private destructor}}
1162 // expected-note@#cwg479-S-dtor {{declared private here}}
1163 }
1164 }
1165 }
1166
1167 namespace cwg480 { // cwg480: yes
1168 struct A { int n; };
1169 struct B : A {};
1170 struct C : virtual B {};
1171 struct D : C {};
1172
1173 int A::*a = &A::n;
1174 int D::*b = a;
1175 // expected-error@-1 {{conversion from pointer to member of class 'cwg480::A' to pointer to member of class 'cwg480::D' via virtual base 'cwg480::B' is not allowed}}
1176
1177 extern int D::*c;
1178 int A::*d = static_cast<int A::*>(c);
1179 // expected-error@-1 {{conversion from pointer to member of class 'cwg480::D' to pointer to member of class 'cwg480::A' via virtual base 'cwg480::B' is not allowed}}
1180
1181 D *e;
1182 A *f = e;
1183 D *g = static_cast<D*>(f);
1184 // expected-error@-1 {{cannot cast 'cwg480::A *' to 'D *' via virtual base 'cwg480::B'}}
1185
1186 extern D &i;
1187 A &j = i;
1188 D &k = static_cast<D&>(j);
1189 // expected-error@-1 {{cannot cast 'A' to 'D &' via virtual base 'cwg480::B'}}
1190 }
1191
1192 namespace cwg481 { // cwg481: 2.8
1193 template<class T, T U> class A { T *x; };
1194 T *x;
1195 // expected-error@-1 {{unknown type name 'T'}}
1196
1197 template<class T *U> class B { T *x; };
1198 T *y; // ok
1199
1200 struct C {
1201 template<class T> void f(class D *p);
1202 };
1203 D *z; // ok
1204
1205 template<typename A = C, typename C = A> struct E {
1206 void f() {
1207 typedef ::cwg481::C c; // #cwg481-c
1208 typedef C c;
1209 // expected-error@-1 {{typedef redefinition with different types ('int' vs '::cwg481::C')}}
1210 // expected-note@#cwg481-E-int {{in instantiation of member function 'cwg481::E<int>::f' requested here}}
1211 // expected-note@#cwg481-c {{previous definition is here}}
1212 }
1213 };
1214 template struct E<>; // ok
1215 template struct E<int>; // #cwg481-E-int
1216
1217 template<template<typename U_no_typo_correction> class A,
1218 A<int> *B,
1219 U_no_typo_correction *C>
1220 // expected-error@-1 {{unknown type name 'U_no_typo_correction'}}
1221 struct F {
1222 U_no_typo_correction *x;
1223 // expected-error@-1 {{unknown type name 'U_no_typo_correction'}}
1224 };
1225
1226 template<template<class H *> class> struct G {
1227 H *x;
1228 };
1229 H *q;
1230
1231 typedef int N;
1232 template<N X, typename N, template<N Y> class T> struct I;
1233 template<char*> struct J;
1234 I<123, char*, J> *j;
1235 }
1236
1237 namespace cwg482 { // cwg482: 3.5
1238 extern int a;
1239 void f();
1240
1241 int cwg482::a = 0;
1242 // expected-warning@-1 {{extra qualification on member 'a'}}
1243 void cwg482::f() {}
1244 // expected-warning@-1 {{extra qualification on member 'f'}}
1245
1246 inline namespace X {
1247 // cxx98-error@-1 {{inline namespaces are a C++11 feature}}
1248 extern int b;
1249 void g();
1250 struct S;
1251 }
1252 int cwg482::b = 0;
1253 // expected-warning@-1 {{extra qualification on member 'b'}}
1254 void cwg482::g() {}
1255 // expected-warning@-1 {{extra qualification on member 'g'}}
1256 struct cwg482::S {};
1257 // expected-warning@-1 {{extra qualification on member 'S'}}
1258
1259 void cwg482::f();
1260 // expected-warning@-1 {{extra qualification on member 'f'}}
1261 void cwg482::g();
1262 // expected-warning@-1 {{extra qualification on member 'g'}}
1263
1264 // FIXME: The following are valid in CWG482's wording, but these are bugs in
1265 // the wording which we deliberately don't implement.
1266 namespace N { typedef int type; }
1267 typedef int N::type;
1268 // expected-error@-1 {{typedef declarator cannot be qualified}}
1269 struct A {
1270 struct B;
1271 struct A::B {};
1272 // expected-error@-1 {{extra qualification on member 'B'}}
1273
1274 #if __cplusplus >= 201103L
1275 enum class C;
1276 enum class A::C {};
1277 // expected-error@-1 {{extra qualification on member 'C'}}
1278 #endif
1279 };
1280 }
1281
1282 namespace cwg483 { // cwg483: yes
1283 namespace climits {
1284 static_assert(__SCHAR_MAX__ >= 127, "");
1285 static_assert(__SHRT_MAX__ >= 32767, "");
1286 static_assert(__INT_MAX__ >= 32767, "");
1287 static_assert(__LONG_MAX__ >= 2147483647, "");
1288 static_assert(__LONG_LONG_MAX__ >= 9223372036854775807, "");
1289 }
1290 namespace cstdint {
1291 static_assert(__PTRDIFF_WIDTH__ >= 16, "");
1292 static_assert(__SIG_ATOMIC_WIDTH__ >= 8, "");
1293 static_assert(__SIZE_WIDTH__ >= 16, "");
1294 static_assert(__WCHAR_WIDTH__ >= 8, "");
1295 static_assert(__WINT_WIDTH__ >= 16, "");
1296 }
1297 }
1298
1299 namespace cwg484 { // cwg484: yes
1300 struct A {
1301 A();
1302 void f();
1303 };
1304 typedef const A CA;
1305 void CA::f() {
1306 this->~CA();
1307 this->CA::~A();
1308 this->CA::A::~A();
1309 }
1310 CA::A() {}
1311
1312 struct B : CA {
1313 B() : CA() {}
1314 void f() { return CA::f(); }
1315 };
1316
1317 struct C;
1318 typedef C CT; // #cwg484-typedef-CT
1319 struct CT {};
1320 // expected-error@-1 {{definition of type 'CT' conflicts with typedef of the same name}}
1321 // expected-note@#cwg484-typedef-CT {{'CT' declared here}}
1322
1323 namespace N {
1324 struct D;
1325 typedef D DT; // #cwg484-typedef-DT
1326 }
1327 struct N::DT {};
1328 // expected-error@-1 {{definition of type 'DT' conflicts with typedef of the same name}}
1329 // expected-note@#cwg484-typedef-DT {{'DT' declared here}}
1330
1331 typedef struct {
1332 S();
1333 // expected-error@-1 {{a type specifier is required for all declarations}}
1334 } S;
1335 }
1336
1337 namespace cwg485 { // cwg485: yes
1338 namespace N {
1339 struct S {};
1340 int operator+(S, S);
1341 template<typename T> int f(S);
1342 }
1343 template<typename T> int f();
1344
1345 N::S s;
1346 int a = operator+(s, s);
1347 int b = f<int>(s);
1348 }
1349
1350 namespace cwg486 { // cwg486: yes
1351 template<typename T> T f(T *); // #cwg486-f
1352 int &f(...);
1353
1354 void g();
1355 int n[10];
1356
1357 void h() {
1358 int &a = f(&g);
1359 int &b = f(&n);
1360 f<void()>(&g);
1361 // expected-error@-1 {{no matching function for call to 'f'}}
1362 // expected-note@#cwg486-f {{candidate template ignored: substitution failure [with T = void ()]: function cannot return function type 'void ()'}}
1363 f<int[10]>(&n);
1364 // expected-error@-1 {{no matching function for call to 'f'}}
1365 // expected-note@#cwg486-f {{candidate template ignored: substitution failure [with T = int[10]]: function cannot return array type 'int[10]'}}
1366 }
1367 }
1368
1369 namespace cwg487 { // cwg487: yes
1370 enum E { e };
1371 int operator+(int, E); // #cwg487-operator-plus
1372 static_assert(4 + e, "");
1373 // expected-error@-1 {{expression is not an integral constant expression}}
1374 // since-cxx11-note@-2 {{non-constexpr function 'operator+' cannot be used in a constant expression}}
1375 // since-cxx11-note@#cwg487-operator-plus {{declared here}}
1376 }
1377
1378 namespace cwg488 { // cwg488: yes c++11
1379 template <typename T> void f(T);
1380 void f(int);
1381 void g() {
1382 // FIXME: It seems CWG thought this should be a SFINAE failure prior to
1383 // allowing local types as template arguments. In C++98, we should either
1384 // allow local types as template arguments or treat this as a SFINAE
1385 // failure.
1386 enum E { e };
1387 f(e);
1388 // cxx98-error@-1 {{template argument uses local type 'E'}}
1389 }
1390 }
1391
1392 // cwg489: na
1393
1394 namespace cwg490 { // cwg490: 2.8
1395 template<typename T> struct X {};
1396
1397 struct A {
1398 typedef int T;
1399 struct K {}; // #cwg490-k
1400
1401 int f(T);
1402 int g(T);
1403 int h(X<T>);
1404 int X<T>::*i(); // #cwg490-i
1405 int K::*j();
1406
1407 template<typename T> T k();
1408
1409 operator X<T>();
1410 };
1411
1412 struct B {
1413 typedef char T;
1414 typedef int U;
1415 friend int A::f(T);
1416 friend int A::g(U);
1417 friend int A::h(X<T>);
1418
1419 // FIXME: Per this DR, these two are valid! That is another defect
1420 // (no number yet...) which will eventually supersede this one.
1421 friend int X<T>::*A::i();
1422 // expected-error@-1 {{return type of out-of-line definition of 'cwg490::A::i' differs from that in the declaration}}
1423 // expected-note@#cwg490-i {{previous declaration is here}}
1424 friend int K::*A::j();
1425 // expected-error@-1 {{use of undeclared identifier 'K'; did you mean 'A::K'?}}
1426 // expected-note@#cwg490-k {{'A::K' declared here}}
1427
1428 // ok, lookup finds B::T, not A::T, so return type matches
1429 friend char A::k<T>();
1430 friend int A::k<U>();
1431
1432 // A conversion-type-id in a conversion-function-id is always looked up in
1433 // the class of the conversion function first.
1434 friend A::operator X<T>();
1435 };
1436 }
1437
1438 namespace cwg491 { // cwg491: dup 413
1439 struct A {} a, b[3] = { a, {} };
1440 A c[2] = { a, {}, b[1] };
1441 // expected-error@-1 {{excess elements in array initializer}}
1442 }
1443
1444 // cwg492 is in cwg492.cpp
1445
1446 namespace cwg493 { // cwg493: dup 976
1447 struct X {
1448 template <class T> operator const T &() const;
1449 };
1450 void f() {
1451 if (X()) {
1452 }
1453 }
1454 }
1455
1456 namespace cwg494 { // cwg494: dup 372
1457 class A {
1458 class B {};
1459 friend class C;
1460 };
1461 class C : A::B {
1462 A::B x;
1463 class D : A::B {
1464 A::B y;
1465 };
1466 };
1467 }
1468
1469 namespace cwg495 { // cwg495: 3.5
1470 template<typename T>
1471 struct S {
1472 operator int() { return T::error; }
1473 template<typename U> operator U();
1474 };
1475 S<int> s;
1476 long n = s;
1477
1478 template<typename T>
1479 struct S2 {
1480 template<typename U> operator U();
1481 operator int() { return T::error; }
1482 };
1483 S2<int> s2;
1484 long n2 = s2;
1485 }
1486
1487 namespace cwg496 { // cwg496: sup 2094
1488 struct A { int n; };
1489 struct B { volatile int n; };
1490 static_assert(__is_trivially_copyable(const int), "");
1491 // This checks the cwg2094 behavior, not cwg496
1492 static_assert(__is_trivially_copyable(volatile int), "");
1493 static_assert(__is_trivially_constructible(A, const A&), "");
1494 static_assert(__is_trivially_constructible(B, const B&), "");
1495 static_assert(__is_trivially_assignable(A, const A&), "");
1496 static_assert(__is_trivially_assignable(B, const B&), "");
1497 }
1498
1499 namespace cwg497 { // cwg497: sup 253
1500 void before() {
1501 struct S {
1502 mutable int i;
1503 };
1504 const S cs;
1505 int S::*pm = &S::i;
1506 cs.*pm = 88;
1507 // expected-error@-1 {{read-only variable is not assignable}}
1508 }
1509
1510 void after() {
1511 struct S {
1512 S() : i(0) {}
1513 mutable int i;
1514 };
1515 const S cs;
1516 int S::*pm = &S::i;
1517 cs.*pm = 88;
1518 // expected-error@-1 {{read-only variable is not assignable}}
1519 }
1520 }
1521
1522 namespace cwg499 { // cwg499: yes
1523 extern char str[];
1524 void f() { throw str; }
1525 }