Debian Codegraph @

clang/test/CXX/drs/cwg0xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-14 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
7 // RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
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 namespace cwg1 { // cwg1: no
15 namespace X { extern "C" void cwg1_f(int a = 1); }
16 namespace Y { extern "C" void cwg1_f(int a = 1); }
17 using X::cwg1_f; using Y::cwg1_f;
18 void g() {
19 cwg1_f(0);
20 // FIXME: This should be rejected, due to the ambiguous default argument.
21 cwg1_f();
22 }
23 namespace X {
24 using Y::cwg1_f;
25 void h() {
26 cwg1_f(0);
27 // FIXME: This should be rejected, due to the ambiguous default argument.
28 cwg1_f();
29 }
30 }
31
32 namespace X {
33 void z(int);
34 }
35 void X::z(int = 1) {} // #cwg1-z
36 namespace X {
37 void z(int = 1);
38 // expected-error@-1 {{redefinition of default argument}}
39 // expected-note@#cwg1-z {{previous definition is here}}
40 }
41
42 void i(int = 1);
43 void j() {
44 void i(int = 1);
45 using cwg1::i;
46 i(0);
47 // FIXME: This should be rejected, due to the ambiguous default argument.
48 i();
49 }
50 void k() {
51 using cwg1::i;
52 void i(int = 1);
53 i(0);
54 // FIXME: This should be rejected, due to the ambiguous default argument.
55 i();
56 }
57 } // namespace cwg1
58
59 namespace cwg3 { // cwg3: 2.7
60 template<typename T> struct A {};
61 template<typename T> void f(T) { A<T> a; } // #cwg3-f-T
62 template void f(int);
63 template<> struct A<int> {};
64 // expected-error@-1 {{explicit specialization of 'cwg3::A<int>' after instantiation}}
65 // expected-note@#cwg3-f-T {{implicit instantiation first required here}}
66 } // namespace cwg3
67
68 namespace cwg4 { // cwg4: 2.8
69 extern "C" {
70 static void cwg4_f(int) {}
71 static void cwg4_f(float) {}
72 void cwg4_g(int) {} // #cwg4-g-int
73 void cwg4_g(float) {}
74 // expected-error@-1 {{conflicting types for 'cwg4_g'}}
75 // expected-note@#cwg4-g-int {{previous definition is here}}
76 }
77 } // namespace cwg4
78
79 namespace cwg5 { // cwg5: 3.1
80 struct A {} a;
81 struct B {
82 B(const A&);
83 B(const B&);
84 };
85 const volatile B b = a;
86
87 struct C { C(C&); };
88 struct D : C {};
89 struct E { operator D&(); } e;
90 const C c = e;
91 } // namespace cwg5
92
93 // cwg6 is in cwg6.cpp
94
95 namespace cwg7 { // cwg7: 3.4
96 class A { public: ~A(); };
97 class B : virtual private A {}; // #cwg7-B
98 class C : public B {} c; // #cwg7-C
99 // expected-error@#cwg7-C {{inherited virtual base class 'A' has private destructor}}
100 // expected-note@#cwg7-C {{in implicit default constructor for 'cwg7::C' first required here}}
101 // expected-note@#cwg7-B {{declared private here}}
102 // expected-error@#cwg7-C {{inherited virtual base class 'A' has private destructor}}
103 // expected-note@#cwg7-C {{in implicit destructor for 'cwg7::C' first required here}}
104 // expected-note@#cwg7-B {{declared private here}}
105 class VeryDerivedC : public B, virtual public A {} vdc;
106
107 class X { ~X(); }; // #cwg7-X
108 class Y : X { ~Y() {} };
109 // expected-error@-1 {{base class 'X' has private destructor}}
110 // expected-note@#cwg7-X {{implicitly declared private here}}
111
112 namespace PR16370 { // This regressed the first time CWG7 was fixed.
113 struct S1 { virtual ~S1(); };
114 struct S2 : S1 {};
115 struct S3 : S2 {};
116 struct S4 : virtual S2 {};
117 struct S5 : S3, S4 {
118 S5();
119 ~S5();
120 };
121 S5::S5() {}
122 }
123 } // namespace cwg7
124
125 namespace cwg8 { // cwg8: dup 45
126 class A {
127 struct U;
128 static const int k = 5;
129 void f();
130 template<typename, int, void (A::*)()> struct T;
131
132 T<U, k, &A::f> *g();
133 };
134 A::T<A::U, A::k, &A::f> *A::g() { return 0; }
135 } // namespace cwg8
136
137 namespace cwg9 { // cwg9: 2.8
138 struct B {
139 protected:
140 int m; // #cwg9-m
141 friend int R1();
142 };
143 struct N : protected B { // #cwg9-N
144 friend int R2();
145 } n;
146 int R1() { return n.m; }
147 // expected-error@-1 {{'m' is a protected member of 'cwg9::B'}}
148 // expected-note@#cwg9-N {{constrained by protected inheritance here}}
149 // expected-note@#cwg9-m {{member is declared here}}
150 int R2() { return n.m; }
151 } // namespace cwg9
152
153 namespace cwg10 { // cwg10: dup 45
154 class A {
155 struct B {
156 A::B *p;
157 };
158 };
159 } // namespace cwg10
160
161 namespace cwg11 { // cwg11: 2.7
162 template<typename T> struct A : T {
163 using typename T::U;
164 U u;
165 };
166 template<typename T> struct B : T {
167 using T::V;
168 V v;
169 // expected-error@-1 {{unknown type name 'V'}}
170 };
171 struct X { typedef int U; };
172 A<X> ax;
173 } // namespace cwg11
174
175 namespace cwg12 { // cwg12: sup 239
176 enum E { e };
177 E &f(E, E = e);
178 void g() {
179 int &f(int, E = e);
180 // Under CWG12, these call two different functions.
181 // Under CWG239, they call the same function.
182 int &b = f(e);
183 int &c = f(1);
184 }
185 } // namespace cwg12
186
187 namespace cwg13 { // cwg13: no
188 extern "C" void f(int);
189 void g(char);
190
191 template<typename T> struct A {
192 A(void (*fp)(T));
193 };
194 template<typename T> int h(void (T));
195
196 A<int> a1(f); // FIXME: We should reject this.
197 A<char> a2(g);
198 int a3 = h(f); // FIXME: We should reject this.
199 int a4 = h(g);
200 } // namespace cwg13
201
202 namespace cwg14 { // cwg14: 3.4
203 namespace X { extern "C" int cwg14_f(); }
204 namespace Y { extern "C" int cwg14_f(); }
205 using namespace X;
206 using namespace Y;
207 int k = cwg14_f();
208
209 class C {
210 int k;
211 friend int Y::cwg14_f();
212 } c;
213 namespace Z {
214 extern "C" int cwg14_f() { return c.k; }
215 }
216
217 namespace X { typedef int T; typedef int U; } // #cwg14-X-U
218 namespace Y { typedef int T; typedef long U; } // #cwg14-Y-U
219 T t; // ok, same type both times
220 U u;
221 // expected-error@-1 {{reference to 'U' is ambiguous}}
222 // expected-note@#cwg14-X-U {{candidate found by name lookup is 'cwg14::X::U'}}
223 // expected-note@#cwg14-Y-U {{candidate found by name lookup is 'cwg14::Y::U'}}
224 } // namespace cwg14
225
226 namespace cwg15 { // cwg15: 2.7
227 template<typename T> void f(int); // #cwg15-f-decl-first
228 template<typename T> void f(int = 0);
229 // expected-error@-1 {{default arguments cannot be added to a function template that has already been declared}}
230 // expected-note@#cwg15-f-decl-first {{previous template declaration is here}}
231 } // namespace cwg15
232
233 namespace cwg16 { // cwg16: 2.8
234 class A { // #cwg16-A
235 void f(); // #cwg16-A-f-decl
236 friend class C;
237 };
238 class B : A {}; // #cwg16-B
239 class C : B {
240 void g() {
241 f();
242 // expected-error@-1 {{'f' is a private member of 'cwg16::A'}}
243 // expected-note@#cwg16-B {{constrained by implicitly private inheritance here}}
244 // expected-note@#cwg16-A-f-decl {{member is declared here}}
245 A::f(); // #cwg16-A-f-call
246 // expected-error@#cwg16-A-f-call {{'A' is a private member of 'cwg16::A'}}
247 // expected-note@#cwg16-B {{constrained by implicitly private inheritance here}}
248 // expected-note@#cwg16-A {{member is declared here}}
249 // expected-error@#cwg16-A-f-call {{cannot cast 'cwg16::C' to its private base class 'A'}}
250 // expected-note@#cwg16-B {{implicitly declared private here}}
251 }
252 };
253 } // namespace cwg16
254
255 namespace cwg17 { // cwg17: 2.7
256 class A {
257 int n;
258 int f();
259 struct C;
260 };
261 struct B : A {} b;
262 int A::f() { return b.n; }
263 struct A::C : A {
264 int g() { return n; }
265 };
266 } // namespace cwg17
267
268 // cwg18: sup 577
269
270 namespace cwg19 { // cwg19: 3.1
271 struct A {
272 int n; // #cwg19-n
273 };
274 struct B : protected A { // #cwg19-B
275 };
276 struct C : B {} c;
277 struct D : B {
278 int get1() { return c.n; }
279 // expected-error@-1 {{'n' is a protected member of 'cwg19::A'}}
280 // expected-note@#cwg19-B {{constrained by protected inheritance here}}
281 // expected-note@#cwg19-n {{member is declared here}}
282 int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here
283 };
284 } // namespace cwg19
285
286 namespace cwg20 { // cwg20: 2.8
287 class X {
288 public:
289 X();
290 private:
291 X(const X&); // #cwg20-X-ctor
292 };
293 X &f();
294 X x = f();
295 // expected-error@-1 {{calling a private constructor of class 'cwg20::X'}}
296 // expected-note@#cwg20-X-ctor {{declared private here}}
297 } // namespace cwg20
298
299 namespace cwg21 { // cwg21: 3.4
300 template<typename T> struct A;
301 struct X {
302 template<typename T = int> friend struct A;
303 // expected-error@-1 {{default template argument not permitted on a friend template}}
304 template<typename T = int> friend struct B;
305 // expected-error@-1 {{default template argument not permitted on a friend template}}
306 };
307 } // namespace cwg21
308
309 namespace cwg22 { // cwg22: sup 481
310 template<typename cwg22_T = cwg22_T> struct X;
311 // expected-error@-1 {{unknown type name 'cwg22_T'}}
312 typedef int T;
313 template<typename T = T> struct Y;
314 } // namespace cwg22
315
316 namespace cwg23 { // cwg23: 2.7
317 template<typename T> void f(T, T); // #cwg23-f-T-T
318 template<typename T> void f(T, int); // #cwg23-f-T-int
319 void g() { f(0, 0); }
320 // expected-error@-1 {{call to 'f' is ambiguous}}
321 // expected-note@#cwg23-f-T-T {{candidate function [with T = int]}}
322 // expected-note@#cwg23-f-T-int {{candidate function [with T = int]}}
323 } // namespace cwg23
324
325 // cwg24: na
326
327 namespace cwg25 { // cwg25: 4
328 struct A {
329 void f() throw(int);
330 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
331 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
332 };
333 void (A::*f)() throw (int);
334 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
335 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
336 void (A::*g)() throw () = f;
337 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
338 // since-cxx17-error@-2 {{different exception specifications}}
339 void (A::*g2)() throw () = 0;
340 void (A::*h)() throw (int, char) = f;
341 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
342 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
343 void (A::*i)() throw () = &A::f;
344 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
345 // since-cxx17-error@-2 {{different exception specifications}}
346 void (A::*i2)() throw () = 0;
347 void (A::*j)() throw (int, char) = &A::f;
348 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
349 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
350 void x() {
351 g2 = f;
352 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
353 // since-cxx17-error@-2 {{different exception specifications}}
354 h = f;
355 i2 = &A::f;
356 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
357 // since-cxx17-error@-2 {{different exception specifications}}
358 j = &A::f;
359 }
360 } // namespace cwg25
361
362 namespace cwg26 { // cwg26: 2.7
363 struct A { A(A, const A & = A()); };
364 // expected-error@-1 {{copy constructor must pass its first argument by reference}}
365 struct B {
366 B();
367 // FIXME: In C++98, we diagnose this twice.
368 B(const B &, B = B());
369 // cxx98-14-error@-1 {{recursive evaluation of default argument}}
370 // cxx98-14-note@-2 {{default argument used here}}
371 // cxx98-error@-3 {{recursive evaluation of default argument}}
372 // cxx98-note@-4 {{default argument used here}}
373 };
374 struct C {
375 static C &f();
376 C(const C &, C = f());
377 // expected-error@-1 {{recursive evaluation of default argument}}
378 // expected-note@-2 {{default argument used here}}
379 };
380 } // namespace cwg26
381
382 namespace cwg27 { // cwg27: 2.7
383 enum E { e } n;
384 E &m = true ? n : n;
385 } // namespace cwg27
386
387 // cwg28: na lib
388
389 namespace cwg29 { // cwg29: 3.4
390 void cwg29_f0(); // #cwg29-f0
391 void g0() { void cwg29_f0(); }
392 extern "C++" void g0_cxx() { void cwg29_f0(); }
393 extern "C" void g0_c() { void cwg29_f0(); }
394 // expected-error@-1 {{declaration of 'cwg29_f0' has a different language linkage}}
395 // expected-note@#cwg29-f0 {{previous declaration is here}}
396
397 extern "C" void cwg29_f1(); // #cwg29-f1
398 void g1() { void cwg29_f1(); }
399 extern "C" void g1_c() { void cwg29_f1(); }
400 extern "C++" void g1_cxx() { void cwg29_f1(); }
401 // expected-error@-1 {{declaration of 'cwg29_f1' has a different language linkage}}
402 // expected-note@#cwg29-f1 {{previous declaration is here}}
403
404 void g2() { void cwg29_f2(); } // #cwg29-f2
405 extern "C" void cwg29_f2();
406 // expected-error@-1 {{declaration of 'cwg29_f2' has a different language linkage}}
407 // expected-note@#cwg29-f2 {{previous declaration is here}}
408
409 extern "C" void g3() { void cwg29_f3(); } // #cwg29-f3
410 extern "C++" void cwg29_f3();
411 // expected-error@-1 {{declaration of 'cwg29_f3' has a different language linkage}}
412 // expected-note@#cwg29-f3 {{previous declaration is here}}
413
414 extern "C++" void g4() { void cwg29_f4(); } // #cwg29-f4
415 extern "C" void cwg29_f4();
416 // expected-error@-1 {{declaration of 'cwg29_f4' has a different language linkage}}
417 // expected-note@#cwg29-f4 {{previous declaration is here}}
418
419 extern "C" void g5();
420 extern "C++" void cwg29_f5();
421 void g5() {
422 void cwg29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
423 }
424
425 extern "C++" void g6();
426 extern "C" void cwg29_f6();
427 void g6() {
428 void cwg29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
429 }
430
431 extern "C" void g7();
432 extern "C++" void cwg29_f7(); // #cwg29-f7
433 extern "C" void g7() {
434 void cwg29_f7();
435 // expected-error@-1 {{declaration of 'cwg29_f7' has a different language linkage}}
436 // expected-note@#cwg29-f7 {{previous declaration is here}}
437 }
438
439 extern "C++" void g8();
440 extern "C" void cwg29_f8(); // #cwg29-f8
441 extern "C++" void g8() {
442 void cwg29_f8();
443 // expected-error@-1 {{declaration of 'cwg29_f8' has a different language linkage}}
444 // expected-note@#cwg29-f8 {{previous declaration is here}}
445 }
446 } // namespace cwg29
447
448 namespace cwg30 { // cwg30: sup 468 c++11
449 struct A {
450 template<int> static int f();
451 } a, *p = &a;
452 // FIXME: It's not clear whether CWG468 applies to C++98 too.
453 int x = A::template f<0>();
454 // cxx98-error@-1 {{'template' keyword outside of a template}}
455 int y = a.template f<0>();
456 // cxx98-error@-1 {{'template' keyword outside of a template}}
457 int z = p->template f<0>();
458 // cxx98-error@-1 {{'template' keyword outside of a template}}
459 } // namespace cwg30
460
461 namespace cwg31 { // cwg31: 2.8
462 class X {
463 private:
464 void operator delete(void*); // #cwg31-delete
465 };
466 // We would call X::operator delete if X() threw (even though it can't,
467 // and even though we allocated the X using ::operator delete).
468 X *p = new X;
469 // expected-error@-1 {{'operator delete' is a private member of 'cwg31::X'}}
470 // expected-note@#cwg31-delete {{declared private here}}
471 } // namespace cwg31
472
473 // cwg32: na
474
475 namespace cwg33 { // cwg33: 9
476 namespace X { struct S; void f(void (*)(S)); } // #cwg33-f-S
477 namespace Y { struct T; void f(void (*)(T)); } // #cwg33-f-T
478 void g(X::S);
479 template<typename Z> Z g(Y::T);
480 void h() { f(&g); }
481 // expected-error@-1 {{call to 'f' is ambiguous}}
482 // expected-note@#cwg33-f-S {{candidate function}}
483 // expected-note@#cwg33-f-T {{candidate function}}
484
485 template<typename T> void t(X::S);
486 template<typename T, typename U = void> void u(X::S);
487 // expected-error@-1 0-1 {{default template arguments for a function template are a C++11 extension}}
488 void templ() { f(t<int>); f(u<int>); }
489
490 // Even though v<int> cannot select the first overload, ADL considers it
491 // and adds namespace Z to the set of associated namespaces, and then picks
492 // Z::f even though that function has nothing to do with any associated type.
493 namespace Z { struct Q; void f(void(*)()); }
494 template<int> Z::Q v();
495 template<typename> void v();
496 void unrelated_templ() { f(v<int>); }
497
498 namespace dependent {
499 struct X {};
500 template<class T> struct Y {
501 friend int operator+(X, void(*)(Y)) {}
502 };
503
504 template<typename T> void f(Y<T>);
505 int use = X() + f<int>;
506 // expected-error@-1 {{invalid operands to binary expression ('X' and 'void (Y<int>)')}}
507 }
508
509 namespace member {
510 struct Q {};
511 struct Y { friend int operator+(Q, Y (*)()); };
512 struct X { template<typename> static Y f(); };
513 int m = Q() + X().f<int>; // ok
514 int n = Q() + (&(X().f<int>)); // ok
515 }
516 } // namespace cwg33
517
518 // cwg34: na
519 // cwg35: dup 178
520
521 namespace cwg36 { // cwg36: 2.8
522 namespace example1 {
523 namespace A {
524 int i;
525 }
526
527 namespace A1 {
528 using A::i;
529 using A::i;
530 }
531
532 void f()
533 {
534 using A::i;
535 using A::i;
536 }
537 }
538
539 namespace example2 {
540 struct A
541 {
542 int i;
543 static int j;
544 };
545
546 struct B : A { };
547 struct C : A { };
548
549 struct D : virtual B, virtual C
550 {
551 using B::i; // #cwg36-ex2-B-i-first
552 using B::i;
553 // expected-error@-1 {{redeclaration of using declaration}}
554 // expected-note@#cwg36-ex2-B-i-first {{previous using declaration}}
555
556 using C::i; // #cwg36-ex2-C-i-first
557 using C::i;
558 // expected-error@-1 {{redeclaration of using declaration}}
559 // expected-note@#cwg36-ex2-C-i-first {{previous using declaration}}
560
561 using B::j; // #cwg36-ex2-B-j-first
562 using B::j;
563 // expected-error@-1 {{redeclaration of using declaration}}
564 // expected-note@#cwg36-ex2-B-j-first {{previous using declaration}}
565
566 using C::j; // #cwg36-ex2-C-j-first
567 using C::j;
568 // expected-error@-1 {{redeclaration of using declaration}}
569 // expected-note@#cwg36-ex2-C-j-first {{previous using declaration}}
570 };
571 }
572
573 namespace example3 {
574 template<typename T>
575 struct A
576 {
577 T i;
578 static T j;
579 };
580
581 template<typename T>
582 struct B : A<T> { };
583 template<typename T>
584 struct C : A<T> { };
585
586 template<typename T>
587 struct D : virtual B<T>, virtual C<T>
588 {
589 using B<T>::i; // #cwg36-ex3-B-i-first
590 using B<T>::i;
591 // expected-error@-1 {{redeclaration of using declaration}}
592 // expected-note@#cwg36-ex3-B-i-first {{previous using declaration}}
593
594 using C<T>::i; // #cwg36-ex3-C-i-first
595 using C<T>::i;
596 // expected-error@-1 {{redeclaration of using declaration}}
597 // expected-note@#cwg36-ex3-C-i-first {{previous using declaration}}
598
599 using B<T>::j; // #cwg36-ex3-B-j-first
600 using B<T>::j;
601 // expected-error@-1 {{redeclaration of using declaration}}
602 // expected-note@#cwg36-ex3-B-j-first {{previous using declaration}}
603
604 using C<T>::j; // #cwg36-ex3-C-j-first
605 using C<T>::j;
606 // expected-error@-1 {{redeclaration of using declaration}}
607 // expected-note@#cwg36-ex3-C-j-first {{previous using declaration}}
608 };
609 }
610 namespace example4 {
611 template<typename T>
612 struct E {
613 T k;
614 };
615
616 template<typename T>
617 struct G : E<T> {
618 using E<T>::k; // #cwg36-E-k-first
619 using E<T>::k;
620 // expected-error@-1 {{redeclaration of using declaration}}
621 // expected-note@#cwg36-E-k-first {{previous using declaration}}
622 };
623 }
624 } // namespace cwg36
625
626 // cwg37: sup 475
627
628 namespace cwg38 { // cwg38: 2.7
629 template<typename T> struct X {};
630 template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }
631 template X<int> operator+<int>(X<int>, X<int>);
632 } // namespace cwg38
633
634 namespace cwg39 { // cwg39: no
635 namespace example1 {
636 struct A { int &f(int); };
637 struct B : A {
638 using A::f;
639 float &f(float);
640 } b;
641 int &r = b.f(0);
642 }
643
644 namespace example2 {
645 struct A {
646 int &x(int); // #cwg39-A-x-decl
647 static int &y(int); // #cwg39-A-y-decl
648 };
649 struct V {
650 int &z(int);
651 };
652 struct B : A, virtual V {
653 using A::x; // #cwg39-using-A-x
654 float &x(float);
655 using A::y; // #cwg39-using-A-y
656 static float &y(float);
657 using V::z;
658 float &z(float);
659 };
660 struct C : A, B, virtual V {} c;
661 /* expected-warning@-1
662 {{direct base 'A' is inaccessible due to ambiguity:
663 struct cwg39::example2::C -> A
664 struct cwg39::example2::C -> B -> A}} */
665 int &x = c.x(0);
666 // expected-error@-1 {{member 'x' found in multiple base classes of different types}}
667 // expected-note@#cwg39-A-x-decl {{member found by ambiguous name lookup}}
668 // expected-note@#cwg39-using-A-x {{member found by ambiguous name lookup}}
669
670 // FIXME: This is valid, because we find the same static data member either way.
671 int &y = c.y(0);
672 // expected-error@-1 {{member 'y' found in multiple base classes of different types}}
673 // expected-note@#cwg39-A-y-decl {{member found by ambiguous name lookup}}
674 // expected-note@#cwg39-using-A-y {{member found by ambiguous name lookup}}
675 int &z = c.z(0);
676 }
677
678 namespace example3 {
679 struct A { static int f(); };
680 struct B : virtual A { using A::f; };
681 struct C : virtual A { using A::f; };
682 struct D : B, C {} d;
683 int k = d.f();
684 }
685
686 namespace example4 {
687 struct A { int n; }; // #cwg39-ex4-A-n
688 struct B : A {};
689 struct C : A {};
690 struct D : B, C { int f() { return n; } };
691 /* expected-error@-1
692 {{non-static member 'n' found in multiple base-class subobjects of type 'A':
693 struct cwg39::example4::D -> B -> A
694 struct cwg39::example4::D -> C -> A}} */
695 // expected-note@#cwg39-ex4-A-n {{member found by ambiguous name lookup}}
696 }
697
698 namespace PR5916 {
699 // FIXME: This is valid.
700 struct A { int n; }; // #cwg39-A-n
701 struct B : A {};
702 struct C : A {};
703 struct D : B, C {};
704 int k = sizeof(D::n); // #cwg39-sizeof
705 /* expected-error@#cwg39-sizeof
706 {{non-static member 'n' found in multiple base-class subobjects of type 'A':
707 struct cwg39::PR5916::D -> B -> A
708 struct cwg39::PR5916::D -> C -> A}} */
709 // expected-note@#cwg39-A-n {{member found by ambiguous name lookup}}
710
711 // expected-error@#cwg39-sizeof {{unknown type name}}
712 #if __cplusplus >= 201103L
713 decltype(D::n) n;
714 /* since-cxx11-error@-1
715 {{non-static member 'n' found in multiple base-class subobjects of type 'A':
716 struct cwg39::PR5916::D -> B -> A
717 struct cwg39::PR5916::D -> C -> A}} */
718 // since-cxx11-note@#cwg39-A-n {{member found by ambiguous name lookup}}
719 #endif
720 }
721 } // namespace cwg39
722
723 // cwg40: na
724
725 namespace cwg41 { // cwg41: 2.7
726 struct S f(S);
727 } // namespace cwg41
728
729 namespace cwg42 { // cwg42: 2.7
730 struct A { static const int k = 0; };
731 struct B : A { static const int k = A::k; };
732 } // namespace cwg42
733
734 // cwg43: na
735
736 namespace cwg44 { // cwg44: sup 727
737 struct A {
738 template<int> void f();
739 template<> void f<0>();
740 };
741 } // namespace cwg44
742
743 namespace cwg45 { // cwg45: 2.7
744 class A {
745 class B {};
746 class C : B {};
747 C c;
748 };
749 } // namespace cwg45
750
751 namespace cwg46 { // cwg46: 2.7
752 template<typename> struct A { template<typename> struct B {}; };
753 template template struct A<int>::B<int>;
754 // expected-error@-1 {{expected unqualified-id}}
755 } // namespace cwg46
756
757 namespace cwg47 { // cwg47: sup 329
758 template<typename T> struct A {
759 friend void f() { T t; } // #cwg47-f
760 // expected-error@-1 {{redefinition of 'f'}}
761 // expected-note@#cwg47-b {{in instantiation of template class 'cwg47::A<float>' requested here}}
762 // expected-note@#cwg47-f {{previous definition is here}}
763 };
764 A<int> a;
765 A<float> b; // #cwg47-b
766
767 void f();
768 void g() { f(); }
769 } // namespace cwg47
770
771 namespace cwg48 { // cwg48: 2.7
772 namespace {
773 struct S {
774 static const int m = 0;
775 static const int n = 0;
776 static const int o = 0;
777 };
778 }
779 int a = S::m;
780 // FIXME: We should produce a 'has internal linkage but is not defined'
781 // diagnostic for 'S::n'.
782 const int &b = S::n;
783 const int S::o;
784 const int &c = S::o;
785 } // namespace cwg48
786
787 namespace cwg49 { // cwg49: 2.8
788 template<int*> struct A {}; // #cwg49-A
789 int k;
790 #if __has_feature(cxx_constexpr)
791 constexpr
792 #endif
793 int *const p = &k; // #cwg49-p
794 A<&k> a;
795 A<p> b; // #cwg49-b
796 // cxx98-error@#cwg49-b {{non-type template argument referring to object 'p' with internal linkage is a C++11 extension}}
797 // cxx98-note@#cwg49-p {{non-type template argument refers to object here}}
798 // cxx98-14-error@#cwg49-b {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
799 // cxx98-14-note@#cwg49-A {{template parameter is declared here}}
800 int *q = &k; // #cwg49-q
801 A<q> c; // #cwg49-c
802 // cxx98-error@#cwg49-c {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
803 // cxx98-note@#cwg49-A {{template parameter is declared here}}
804 // cxx11-14-error@#cwg49-c {{non-type template argument of type 'int *' is not a constant expression}}
805 // cxx11-14-note@#cwg49-c {{read of non-constexpr variable 'q' is not allowed in a constant expression}}
806 // cxx11-14-note@#cwg49-q {{declared here}}
807 // cxx11-14-note@#cwg49-A {{template parameter is declared here}}
808 // since-cxx17-error@#cwg49-c {{non-type template argument is not a constant expression}}
809 // since-cxx17-note@#cwg49-c {{read of non-constexpr variable 'q' is not allowed in a constant expression}}
810 // since-cxx17-note@#cwg49-q {{declared here}}
811 } // namespace cwg49
812
813 namespace cwg50 { // cwg50: 2.7
814 struct X; // #cwg50-X
815 extern X *p;
816 X *q = (X*)p;
817 X *r = static_cast<X*>(p);
818 X *s = const_cast<X*>(p);
819 X *t = reinterpret_cast<X*>(p);
820 X *u = dynamic_cast<X*>(p);
821 // expected-error@-1 {{'cwg50::X' is an incomplete type}}
822 // expected-note@#cwg50-X {{forward declaration of 'cwg50::X'}}
823 } // namespace cwg50
824
825 namespace cwg51 { // cwg51: 2.8
826 struct A {};
827 struct B : A {};
828 struct S {
829 operator A&();
830 operator B&();
831 } s;
832 A &a = s;
833 } // namespace cwg51
834
835 namespace cwg52 { // cwg52: 2.8
836 struct A { int n; }; // #cwg52-A
837 struct B : private A {} b; // #cwg52-B
838 int k = b.A::n; // #cwg52-k
839 // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
840 // expected-error@#cwg52-k {{'A' is a private member of 'cwg52::A'}}
841 // expected-note@#cwg52-B {{constrained by private inheritance here}}
842 // expected-note@#cwg52-A {{member is declared here}}
843 // expected-error@#cwg52-k {{cannot cast 'struct B' to its private base class 'A'}}
844 // expected-note@#cwg52-B {{declared private here}}
845 } // namespace cwg52
846
847 namespace cwg53 { // cwg53: 2.7
848 int n = 0;
849 enum E { e } x = static_cast<E>(n);
850 } // namespace cwg53
851
852 namespace cwg54 { // cwg54: 2.8
853 struct A { int a; } a;
854 struct V { int v; } v;
855 struct B : private A, virtual V { int b; } b; // #cwg54-B
856
857 A &sab = static_cast<A&>(b);
858 // expected-error@-1 {{cannot cast 'struct B' to its private base class 'A'}}
859 // expected-note@#cwg54-B {{declared private here}}
860 A *spab = static_cast<A*>(&b);
861 // expected-error@-1 {{cannot cast 'struct B' to its private base class 'A'}}
862 // expected-note@#cwg54-B {{declared private here}}
863 int A::*smab = static_cast<int A::*>(&B::b);
864 // expected-error@-1 {{cannot cast 'cwg54::B' to its private base class 'A'}}
865 // expected-note@#cwg54-B {{declared private here}}
866 B &sba = static_cast<B&>(a);
867 // expected-error@-1 {{cannot cast private base class 'cwg54::A' to 'cwg54::B'}}
868 // expected-note@#cwg54-B {{declared private here}}
869 B *spba = static_cast<B*>(&a);
870 // expected-error@-1 {{cannot cast private base class 'cwg54::A' to 'cwg54::B'}}
871 // expected-note@#cwg54-B {{declared private here}}
872 int B::*smba = static_cast<int B::*>(&A::a);
873 // expected-error@-1 {{cannot cast private base class 'A' to 'B'}}
874 // expected-note@#cwg54-B {{declared private here}}
875
876 V &svb = static_cast<V&>(b);
877 V *spvb = static_cast<V*>(&b);
878 int V::*smvb = static_cast<int V::*>(&B::b);
879 // expected-error@-1 {{conversion from pointer to member of class 'cwg54::B' to pointer to member of class 'V' via virtual base 'cwg54::V' is not allowed}}
880 B &sbv = static_cast<B&>(v);
881 // expected-error@-1 {{cannot cast 'struct V' to 'B &' via virtual base 'cwg54::V'}}
882 B *spbv = static_cast<B*>(&v);
883 // expected-error@-1 {{cannot cast 'cwg54::V *' to 'B *' via virtual base 'cwg54::V'}}
884 int B::*smbv = static_cast<int B::*>(&V::v);
885 // expected-error@-1 {{conversion from pointer to member of class 'V' to pointer to member of class 'B' via virtual base 'cwg54::V' is not allowed}}
886
887 A &cab = (A&)(b);
888 A *cpab = (A*)(&b);
889 int A::*cmab = (int A::*)(&B::b);
890 B &cba = (B&)(a);
891 B *cpba = (B*)(&a);
892 int B::*cmba = (int B::*)(&A::a);
893
894 V &cvb = (V&)(b);
895 V *cpvb = (V*)(&b);
896 int V::*cmvb = (int V::*)(&B::b);
897 // expected-error@-1 {{conversion from pointer to member of class 'cwg54::B' to pointer to member of class 'V' via virtual base 'cwg54::V' is not allowed}}
898 B &cbv = (B&)(v);
899 // expected-error@-1 {{cannot cast 'struct V' to 'B &' via virtual base 'cwg54::V'}}
900 B *cpbv = (B*)(&v);
901 // expected-error@-1 {{cannot cast 'cwg54::V *' to 'B *' via virtual base 'cwg54::V'}}
902 int B::*cmbv = (int B::*)(&V::v);
903 // expected-error@-1 {{conversion from pointer to member of class 'V' to pointer to member of class 'B' via virtual base 'cwg54::V' is not allowed}}
904 } // namespace cwg54
905
906 namespace cwg55 { // cwg55: 2.7
907 enum E { e = 5 };
908 static_assert(e + 1 == 6, "");
909 } // namespace cwg55
910
911 namespace cwg56 { // cwg56: 2.7
912 struct A {
913 typedef int T; // #cwg56-typedef-int-T-first
914 typedef int T;
915 // expected-error@-1 {{redefinition of 'T'}}
916 // expected-note@#cwg56-typedef-int-T-first {{previous definition is here}}
917 };
918 struct B {
919 struct X;
920 typedef X X; // #cwg56-typedef-X-X-first
921 typedef X X;
922 // expected-error@-1 {{redefinition of 'X'}}
923 // expected-note@#cwg56-typedef-X-X-first {{previous definition is here}}
924 };
925 } // namespace cwg56
926
927 namespace cwg58 { // cwg58: 3.1
928 // FIXME: Ideally, we should have a CodeGen test for this.
929 #if __cplusplus >= 201103L
930 enum E1 { E1_0 = 0, E1_1 = 1 };
931 enum E2 { E2_0 = 0, E2_m1 = -1 };
932 struct X { E1 e1 : 1; E2 e2 : 1; };
933 static_assert(X{E1_1, E2_m1}.e1 == 1, "");
934 static_assert(X{E1_1, E2_m1}.e2 == -1, "");
935 #endif
936 } // namespace cwg58
937
938 namespace cwg59 { // cwg59: 2.7
939 #pragma clang diagnostic push
940 #pragma clang diagnostic ignored "-Wdeprecated-volatile"
941 template<typename T> struct convert_to { operator T() const; };
942 struct A {}; // #cwg59-A
943 struct B : A {}; // #cwg59-B
944
945 A a1 = convert_to<A>();
946 A a2 = convert_to<A&>();
947 A a3 = convert_to<const A>();
948 A a4 = convert_to<const volatile A>();
949 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::A'}}
950 // cxx98-14-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::A') would lose volatile qualifier}}
951 // cxx11-14-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::A') would lose const and volatile qualifiers}}
952 // cxx98-14-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
953 A a5 = convert_to<const volatile A&>();
954 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::A'}}
955 // expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::A') would lose volatile qualifier}}
956 // since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::A') would lose const and volatile qualifiers}}
957 // expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
958
959 B b1 = convert_to<B>();
960 B b2 = convert_to<B&>();
961 B b3 = convert_to<const B>();
962 B b4 = convert_to<const volatile B>();
963 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
964 // cxx98-14-note@#cwg59-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::B') would lose volatile qualifier}}
965 // cxx11-14-note@#cwg59-B {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::B') would lose const and volatile qualifiers}}
966 // cxx98-14-note@#cwg59-B {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
967 B b5 = convert_to<const volatile B&>();
968 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
969 // expected-note@#cwg59-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::B') would lose volatile qualifier}}
970 // since-cxx11-note@#cwg59-B {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::B') would lose const and volatile qualifiers}}
971 // expected-note@#cwg59-B {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
972
973 A c1 = convert_to<B>();
974 A c2 = convert_to<B&>();
975 A c3 = convert_to<const B>();
976 A c4 = convert_to<const volatile B>();
977 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
978 // expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'const A &' for 1st argument}}
979 // since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'A &&' for 1st argument}}
980 // expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
981 A c5 = convert_to<const volatile B&>();
982 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
983 // expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'const A &' for 1st argument}}
984 // since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'A &&' for 1st argument}}
985 // expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
986
987 int n1 = convert_to<int>();
988 int n2 = convert_to<int&>();
989 int n3 = convert_to<const int>();
990 int n4 = convert_to<const volatile int>();
991 int n5 = convert_to<const volatile int&>();
992 #pragma clang diagnostic pop
993 } // namespace cwg59
994
995 namespace cwg60 { // cwg60: 2.7
996 void f(int &);
997 int &f(...);
998 const int k = 0;
999 int &n = f(k);
1000 } // namespace cwg60
1001
1002 namespace cwg61 { // cwg61: 3.4
1003 struct X {
1004 static void f();
1005 } x;
1006 struct Y {
1007 static void f();
1008 static void f(int);
1009 } y;
1010 // This is (presumably) valid, because x.f does not refer to an overloaded
1011 // function name.
1012 void (*p)() = &x.f;
1013 void (*q)() = &y.f;
1014 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
1015 void (*r)() = y.f;
1016 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
1017 } // namespace cwg61
1018
1019 namespace cwg62 { // cwg62: 2.9
1020 struct A {
1021 struct { int n; } b;
1022 };
1023 template<typename T> struct X {};
1024 template<typename T> T get() { return get<T>(); }
1025 template<typename T> int take(T) { return 0; }
1026
1027 X<A> x1;
1028 A a = get<A>();
1029
1030 typedef struct { } *NoNameForLinkagePtr; // #cwg62-unnamed
1031 NoNameForLinkagePtr noNameForLinkagePtr;
1032
1033 struct Danger {
1034 NoNameForLinkagePtr p;
1035 };
1036
1037 X<NoNameForLinkagePtr> x2;
1038 // cxx98-error@-1 {{template argument uses unnamed type}}
1039 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1040 X<const NoNameForLinkagePtr> x3;
1041 // cxx98-error@-1 {{template argument uses unnamed type}}
1042 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1043 NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>();
1044 // cxx98-error@-1 {{template argument uses unnamed type}}
1045 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1046 // cxx98-note@-3 {{while substituting explicitly-specified template arguments}}
1047 NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>();
1048 // cxx98-error@-1 {{template argument uses unnamed type}}
1049 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1050 // cxx98-note@-3 {{while substituting explicitly-specified template arguments}}
1051 int n1 = take(noNameForLinkagePtr);
1052 // cxx98-error@-1 {{template argument uses unnamed type}}
1053 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1054 // cxx98-note@-3 {{while substituting deduced template arguments}}
1055
1056 X<Danger> x4;
1057
1058 void f() {
1059 struct NoLinkage {};
1060 X<NoLinkage> a;
1061 // cxx98-error@-1 {{template argument uses local type }}
1062 X<const NoLinkage> b;
1063 // cxx98-error@-1 {{template argument uses local type }}
1064 get<NoLinkage>();
1065 // cxx98-error@-1 {{template argument uses local type }}
1066 // cxx98-note@-2 {{while substituting explicitly-specified template arguments}}
1067 get<const NoLinkage>();
1068 // cxx98-error@-1 {{template argument uses local type }}
1069 // cxx98-note@-2 {{while substituting explicitly-specified template arguments}}
1070 X<void (*)(NoLinkage A::*)> c;
1071 // cxx98-error@-1 {{template argument uses local type }}
1072 X<int NoLinkage::*> d;
1073 // cxx98-error@-1 {{template argument uses local type }}
1074 }
1075 } // namespace cwg62
1076
1077 namespace cwg63 { // cwg63: 2.7
1078 template<typename T> struct S { typename T::error e; };
1079 extern S<int> *p;
1080 void *q = p;
1081 } // namespace cwg63
1082
1083 namespace cwg64 { // cwg64: 2.7
1084 template<class T> void f(T);
1085 template<class T> void f(T*);
1086 template<> void f(int*);
1087 template<> void f<int>(int*);
1088 template<> void f(int);
1089 } // namespace cwg64
1090
1091 // cwg65: na
1092
1093 namespace cwg66 { // cwg66: no
1094 namespace X {
1095 int f(int n); // #cwg66-f-first
1096 }
1097 using X::f;
1098 namespace X {
1099 int f(int n = 0);
1100 int f(int, int);
1101 }
1102 // FIXME: The first two calls here should be accepted.
1103 int a = f();
1104 // expected-error@-1 {{no matching function for call to 'f'}}
1105 // expected-note@#cwg66-f-first {{candidate function not viable: requires single argument 'n', but no arguments were provided}}
1106 int b = f(1);
1107 int c = f(1, 2);
1108 // expected-error@-1 {{no matching function for call to 'f'}}
1109 // expected-note@#cwg66-f-first {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
1110 } // namespace cwg66
1111
1112 // cwg67: na
1113
1114 namespace cwg68 { // cwg68: 2.8
1115 template<typename T> struct X {};
1116 struct ::cwg68::X<int> x1;
1117 struct ::cwg68::template X<int> x2;
1118 // cxx98-error@-1 {{'template' keyword outside of a template}}
1119 struct Y {
1120 friend struct X<int>;
1121 friend struct ::cwg68::X<char>;
1122 friend struct ::cwg68::template X<double>;
1123 // cxx98-error@-1 {{'template' keyword outside of a template}}
1124 };
1125 template<typename>
1126 struct Z {
1127 friend struct ::cwg68::template X<double>;
1128 friend typename ::cwg68::X<double>;
1129 // cxx98-error@-1 {{unelaborated friend declaration is a C++11 extension; specify 'struct' to befriend 'typename ::cwg68::X<double>'}}
1130 };
1131 } // namespace cwg68
1132
1133 namespace cwg69 { // cwg69: 9
1134 template<typename T> static void f() {} // #cwg69-f
1135 // FIXME: Should we warn here?
1136 inline void g() { f<int>(); }
1137 extern template void f<char>();
1138 // cxx98-error@-1 {{extern templates are a C++11 extension}}
1139 // expected-error@-2 {{explicit instantiation declaration of 'f' with internal linkage}}
1140 template<void(*)()> struct Q {};
1141 Q<&f<int> > q;
1142 // cxx98-error@-1 {{non-type template argument referring to function 'f<int>' with internal linkage is a C++11 extension}}
1143 // cxx98-note@#cwg69-f {{non-type template argument refers to function here}}
1144 } // namespace cwg69
1145
1146 namespace cwg70 { // cwg70: 2.7
1147 template<int> struct A {};
1148 template<int I, int J> int f(int (&)[I + J], A<I>, A<J>);
1149 int arr[7];
1150 int k = f(arr, A<3>(), A<4>());
1151 } // namespace cwg70
1152
1153 // cwg71: na
1154 // cwg72: dup 69
1155
1156 namespace cwg73 { // cwg73: sup 1652
1157 #if __cplusplus >= 201103L
1158 int a, b;
1159 static_assert(&a + 1 != &b, "");
1160 // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
1161 // since-cxx11-note@-2 {{comparison against pointer '&a + 1' that points past the end of a complete object has unspecified value}}
1162 #endif
1163 } // namespace cwg73
1164
1165 namespace cwg74 { // cwg74: 2.7
1166 enum E { k = 5 };
1167 int (*p)[k] = new int[k][k];
1168 } // namespace cwg74
1169
1170 namespace cwg75 { // cwg75: 2.7
1171 struct S {
1172 static int n = 0;
1173 // expected-error@-1 {{non-const static data member must be initialized out of line}}
1174 };
1175 } // namespace cwg75
1176
1177 namespace cwg76 { // cwg76: 2.7
1178 const volatile int n = 1;
1179 static_assert(n, "");
1180 // expected-error@-1 {{static assertion expression is not an integral constant expression}}
1181 // expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}
1182 } // namespace cwg76
1183
1184 namespace cwg77 { // cwg77: 2.7
1185 struct A {
1186 struct B {};
1187 friend struct B;
1188 };
1189 } // namespace cwg77
1190
1191 namespace cwg78 { // cwg78: sup ????
1192 // Under CWG78, this is valid, because 'k' has static storage duration, so is
1193 // zero-initialized.
1194 const int k;
1195 // expected-error@-1 {{default initialization of an object of const type 'const int'}}
1196 } // namespace cwg78
1197
1198 // cwg79: na
1199
1200 namespace cwg80 { // cwg80: 2.9
1201 struct A {
1202 int A;
1203 };
1204 struct B {
1205 static int B;
1206 // expected-error@-1 {{member 'B' has the same name as its class}}
1207 };
1208 struct C {
1209 int C;
1210 // expected-error@-1 {{member 'C' has the same name as its class}}
1211 C();
1212 };
1213 struct D {
1214 D();
1215 int D;
1216 // expected-error@-1 {{member 'D' has the same name as its class}}
1217 };
1218 } // namespace cwg80
1219
1220 // cwg81: na
1221 // cwg82: dup 48
1222
1223 namespace cwg83 { // cwg83: 2.7
1224 int &f(const char*);
1225 char &f(char *);
1226 int &k = f("foo");
1227 } // namespace cwg83
1228
1229 namespace cwg84 { // cwg84: 2.7
1230 struct B;
1231 struct A { operator B() const; };
1232 struct C {};
1233 struct B {
1234 B(B&); // #cwg84-copy-ctor
1235 B(C); // #cwg84-ctor-from-C
1236 operator C() const;
1237 };
1238 A a;
1239 // Cannot use B(C) / operator C() pair to construct the B from the B temporary
1240 // here. In C++17, we initialize the B object directly using 'A::operator B()'.
1241 B b = a;
1242 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'B'}}
1243 // cxx98-14-note@#cwg84-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1244 // cxx98-14-note@#cwg84-ctor-from-C {{candidate constructor not viable: no known conversion from 'B' to 'C' for 1st argument}}
1245 } // namespace cwg84
1246
1247 namespace cwg85 { // cwg85: 3.4
1248 struct A {
1249 struct B;
1250 struct B {}; // #cwg85-B-def
1251 struct B;
1252 // expected-error@-1 {{class member cannot be redeclared}}
1253 // expected-note@#cwg85-B-def {{previous declaration is here}}
1254
1255 union U;
1256 union U {}; // #cwg85-U-def
1257 union U;
1258 // expected-error@-1 {{class member cannot be redeclared}}
1259 // expected-note@#cwg85-U-def {{previous declaration is here}}
1260
1261 #if __cplusplus >= 201103L
1262 enum E1 : int;
1263 enum E1 : int { e1 }; // #cwg85-E1-def
1264 enum E1 : int;
1265 // since-cxx11-error@-1 {{class member cannot be redeclared}}
1266 // since-cxx11-note@#cwg85-E1-def {{previous declaration is here}}
1267
1268 enum class E2;
1269 enum class E2 { e2 }; // #cwg85-E2-def
1270 enum class E2;
1271 // since-cxx11-error@-1 {{class member cannot be redeclared}}
1272 // since-cxx11-note@#cwg85-E2-def {{previous declaration is here}}
1273 #endif
1274 };
1275
1276 template <typename T>
1277 struct C {
1278 struct B {}; // #cwg85-C-B-def
1279 struct B;
1280 // expected-error@-1 {{class member cannot be redeclared}}
1281 // expected-note@#cwg85-C-B-def {{previous declaration is here}}
1282 };
1283 } // namespace cwg85
1284
1285 // cwg86: dup 446
1286
1287 namespace cwg87 { // cwg87: no
1288 // FIXME: Superseded by cwg1975
1289 template<typename T> struct X {};
1290 // FIXME: This is invalid.
1291 X<void() throw()> x;
1292 // This is valid under cwg87 but not under cwg1975.
1293 X<void(void() throw())> y;
1294 } // namespace cwg87
1295
1296 namespace cwg88 { // cwg88: 2.8
1297 template<typename T> struct S {
1298 static const int a = 1; // #cwg88-a
1299 static const int b;
1300 };
1301 template<> const int S<int>::a = 4;
1302 // expected-error@-1 {{static data member 'a' already has an initializer}}
1303 // expected-note@#cwg88-a {{previous initialization is here}}
1304 template<> const int S<int>::b = 4;
1305 } // namespace cwg88
1306
1307 // cwg89: na
1308
1309 namespace cwg90 { // cwg90: 2.7
1310 struct A {
1311 template<typename T> friend void cwg90_f(T);
1312 };
1313 struct B : A {
1314 template<typename T> friend void cwg90_g(T);
1315 struct C {};
1316 union D {};
1317 };
1318 struct E : B {};
1319 struct F : B::C {};
1320
1321 void test() {
1322 cwg90_f(A());
1323 cwg90_f(B());
1324 cwg90_f(B::C());
1325 // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}
1326 cwg90_f(B::D());
1327 // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}
1328 cwg90_f(E());
1329 cwg90_f(F());
1330 // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}
1331
1332 cwg90_g(A());
1333 // expected-error@-1 {{use of undeclared identifier 'cwg90_g'}}
1334 cwg90_g(B());
1335 cwg90_g(B::C());
1336 cwg90_g(B::D());
1337 cwg90_g(E());
1338 cwg90_g(F());
1339 // expected-error@-1 {{use of undeclared identifier 'cwg90_g'}}
1340 }
1341 } // namespace cwg90
1342
1343 namespace cwg91 { // cwg91: 2.7
1344 union U { friend int f(U); };
1345 int k = f(U());
1346 } // namespace cwg91
1347
1348 namespace cwg92 { // cwg92: 4 c++17
1349 void f() throw(int, float);
1350 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1351 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1352 void (*p)() throw(int) = &f; // #cwg92-p
1353 // since-cxx17-error@#cwg92-p {{ISO C++17 does not allow dynamic exception specifications}}
1354 // since-cxx17-note@#cwg92-p {{use 'noexcept(false)' instead}}
1355 // cxx98-14-error@#cwg92-p {{target exception specification is not superset of source}}
1356 // since-cxx17-warning@#cwg92-p {{target exception specification is not superset of source}}
1357 void (*q)() throw(int);
1358 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1359 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1360 void (**pp)() throw() = &q;
1361 // cxx98-14-error@-1 {{exception specifications are not allowed beyond a single level of indirection}}
1362 // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (**)() throw()' with an rvalue of type 'void (**)() throw(int)'}}
1363
1364 void g(void() throw()); // #cwg92-g
1365 // cxx98-14-warning@-1 {{mangled name of 'g' will change in C++17 due to non-throwing exception specification in function signature}}
1366 void h() throw() {
1367 g(f);
1368 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1369 // since-cxx17-error@-2 {{no matching function for call to 'g'}}
1370 // since-cxx17-note@#cwg92-g {{candidate function not viable: no known conversion from 'void () throw(int, float)' to 'void (*)() throw()' for 1st argument}}
1371 g(q);
1372 // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1373 // since-cxx17-error@-2 {{no matching function for call to 'g'}}
1374 // since-cxx17-note@#cwg92-g {{candidate function not viable: no known conversion from 'void (*)() throw(int)' to 'void (*)() throw()' for 1st argument}}
1375 }
1376
1377 // Prior to C++17, this is OK because the exception specification is not
1378 // considered in this context. In C++17, we *do* perform an implicit
1379 // conversion (which performs initialization), and the exception specification
1380 // is part of the type of the parameter, so this is invalid.
1381 template<void() throw()> struct X {}; // since-cxx17-note {{template parameter is declared here}}
1382 X<&f> xp;
1383 // since-cxx17-error@-1 {{value of type 'void (*)() throw(int, float)' is not implicitly convertible to 'void (*)() throw()'}}
1384
1385 template<void() throw(int)> struct Y {};
1386 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1387 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1388 Y<&h> yp; // ok
1389 } // namespace cwg92
1390
1391 // cwg93: na
1392
1393 namespace cwg94 { // cwg94: 2.7
1394 struct A { static const int n = 5; };
1395 int arr[A::n];
1396 } // namespace cwg94
1397
1398 namespace cwg95 { // cwg95: 3.3
1399 struct A;
1400 struct B;
1401 namespace N {
1402 class C {
1403 friend struct A;
1404 friend struct B;
1405 static void f(); // #cwg95-C-f
1406 };
1407 struct A *p; // cwg95::A, not cwg95::N::A.
1408 }
1409 A *q = N::p; // ok, same type
1410 struct B { void f() { N::C::f(); } };
1411 // expected-error@-1 {{'f' is a private member of 'cwg95::N::C'}}
1412 // expected-note@#cwg95-C-f {{implicitly declared private here}}
1413 } // namespace cwg95
1414
1415 namespace cwg96 { // cwg96: sup P1787
1416 struct A {
1417 void f(int);
1418 template<typename T> int f(T);
1419 template<typename T> struct S {};
1420 } a;
1421 template<template<typename> class X> struct B {};
1422
1423 template<typename T>
1424 void test() {
1425 int k1 = a.template f<int>(0);
1426 // FIXME: This is ill-formed, because 'f' is not a template-id and does not
1427 // name a class template.
1428 // FIXME: What about alias templates?
1429 int k2 = a.template f(1);
1430 // expected-error@-1 {{a template argument list is expected after a name prefixed by the template keyword}}
1431 A::template S<int> s;
1432 B<A::template S> b;
1433 }
1434 } // namespace cwg96
1435
1436 namespace cwg97 { // cwg97: 2.7
1437 struct A {
1438 static const int a = false;
1439 static const int b = !a;
1440 };
1441 } // namespace cwg97
1442
1443 namespace cwg98 { // cwg98: 2.7
1444 void test(int n) {
1445 switch (n) {
1446 try { // #cwg98-try
1447 case 0:
1448 // expected-error@-1 {{cannot jump from switch statement to this case label}}
1449 // expected-note@#cwg98-try {{jump bypasses initialization of try block}}
1450 x:
1451 throw n;
1452 } catch (...) { // #cwg98-catch
1453 case 1:
1454 // expected-error@-1 {{cannot jump from switch statement to this case label}}
1455 // expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}
1456 y:
1457 throw n;
1458 }
1459 case 2:
1460 goto x;
1461 // expected-error@-1 {{cannot jump from this goto statement to its label}}
1462 // expected-note@#cwg98-try {{jump bypasses initialization of try block}}
1463 case 3:
1464 goto y;
1465 // expected-error@-1 {{cannot jump from this goto statement to its label}}
1466 // expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}
1467 }
1468 }
1469 } // namespace cwg98
1470
1471 namespace cwg99 { // cwg99: sup 214
1472 template<typename T> void f(T&);
1473 template<typename T> int &f(const T&);
1474 const int n = 0;
1475 int &r = f(n);
1476 } // namespace cwg99