Debian Codegraph @

clang/test/CXX/drs/cwg1xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,cxx98-14,cxx98-17,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
7
8 #if __cplusplus == 199711L
9 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
10 // cxx98-error@-1 {{variadic macros are a C99 feature}}
11 #endif
12
13 #if __cplusplus == 199711L
14 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
15 #else
16 #define __enable_constant_folding
17 #endif
18
19 namespace cwg100 { // cwg100: yes
20 template<const char (*)[4]> struct A {}; // #cwg100-A
21 template<const char (&)[4]> struct B {}; // #cwg100-B
22 template<const char *> struct C {}; // #cwg100-C
23 template<const char &> struct D {}; // #cwg100-D
24 A<&"foo"> a; // #cwg100-a
25 // cxx98-14-error@#cwg100-a {{non-type template argument does not refer to any declaration}}
26 // cxx98-14-note@#cwg100-A {{template parameter is declared here}}
27 // since-cxx17-error@#cwg100-a {{pointer to string literal is not allowed in a template argument}}
28 B<"bar"> b; // #cwg100-b
29 // cxx98-14-error@#cwg100-b {{non-type template argument does not refer to any declaration}}
30 // cxx98-14-note@#cwg100-B {{template parameter is declared here}}
31 // since-cxx17-error@#cwg100-b {{reference to string literal is not allowed in a template argument}}
32 C<"baz"> c; // #cwg100-c
33 // cxx98-14-error@#cwg100-c {{non-type template argument does not refer to any declaration}}
34 // cxx98-14-note@#cwg100-C {{template parameter is declared here}}
35 // since-cxx17-error@#cwg100-c {{pointer to subobject of string literal is not allowed in a template argument}}
36 D<*"quux"> d; // #cwg100-d
37 // cxx98-14-error@#cwg100-d {{non-type template argument does not refer to any declaration}}
38 // cxx98-14-note@#cwg100-D {{template parameter is declared here}}
39 // since-cxx17-error@#cwg100-d {{reference to subobject of string literal is not allowed in a template argument}}
40 }
41
42 namespace cwg101 { // cwg101: 3.5
43 extern "C" void cwg101_f();
44 typedef unsigned size_t;
45 namespace X {
46 extern "C" void cwg101_f();
47 typedef unsigned size_t;
48 }
49 using X::cwg101_f;
50 using X::size_t;
51 extern "C" void cwg101_f();
52 typedef unsigned size_t;
53 }
54
55 namespace cwg102 { // cwg102: yes
56 namespace A {
57 template<typename T> T f(T a, T b) { return a + b; }
58 // expected-error@-1 {{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}}
59 // expected-note@#cwg102-instantiation {{in instantiation of function template specialization 'cwg102::A::f<cwg102::B::S>' requested here}}
60 // expected-note@#cwg102-operator-plus {{'operator+' should be declared prior to the call site or in namespace 'cwg102::B'}}
61 }
62 namespace B {
63 struct S {};
64 }
65 B::S operator+(B::S, B::S); // #cwg102-operator-plus
66 template B::S A::f(B::S, B::S); // #cwg102-instantiation
67 }
68
69 // cwg103: na
70 // cwg104: na lib
71 // cwg105: na
72
73 namespace cwg106 { // cwg106: sup 540
74 typedef int &r1;
75 typedef r1 &r1;
76 typedef const r1 r1;
77 // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}}
78 typedef const r1 &r1;
79 // expected-warning@-1 {{'const' qualifier on reference type 'r1' (aka 'int &') has no effect}}
80
81 typedef const int &r2;
82 typedef r2 &r2;
83 typedef const r2 r2;
84 // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}}
85 typedef const r2 &r2;
86 // expected-warning@-1 {{'const' qualifier on reference type 'r2' (aka 'const int &') has no effect}}
87 }
88
89 namespace cwg107 { // cwg107: yes
90 struct S {};
91 extern "C" S operator+(S, S) { return S(); }
92 }
93
94 namespace cwg108 { // cwg108: 2.9
95 template<typename T> struct A {
96 struct B { typedef int X; };
97 B::X x;
98 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}}
99 struct C : B { X x; };
100 // expected-error@-1 {{unknown type name 'X'}}
101 };
102 template<> struct A<int>::B { int X; };
103 }
104
105 namespace cwg109 { // cwg109: yes
106 struct A { template<typename T> void f(T); };
107 template<typename T> struct B : T {
108 using T::template f;
109 // expected-error@-1 {{'template' keyword not permitted here}}
110 using T::template f<int>;
111 // expected-error@-1 {{'template' keyword not permitted here}}
112 // expected-error@-2 {{using declaration cannot refer to a template specialization}}
113 // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid.
114 using T::f<int>;
115 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}
116 // expected-error@-2 {{using declaration cannot refer to a template specialization}}
117 void g() { this->f<int>(123); }
118 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}
119 };
120 }
121
122 namespace cwg111 { // cwg111: dup 535
123 struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };
124 struct B : A { B(); }; // #cwg111-B
125 const B b1;
126 B b2(b1);
127 // expected-error@-1 {{no matching constructor for initialization of 'B'}}
128 // expected-note@#cwg111-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const B') would lose const qualifier}}
129 // expected-note@#cwg111-B {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
130 }
131
132 namespace cwg112 { // cwg112: yes
133 struct T { int n; };
134 typedef T Arr[1];
135
136 const T a1[1] = {}; // #cwg112-a1
137 volatile T a2[1] = {};
138 const Arr a3 = {}; // #cwg112-a3
139 volatile Arr a4 = {};
140 template<const volatile T*> struct X {};
141 // FIXME: Test this somehow in C++11 and on.
142 X<a1> x1;
143 // cxx98-error@-1 {{non-type template argument referring to object 'a1' with internal linkage is a C++11 extension}}
144 // cxx98-note@#cwg112-a1 {{non-type template argument refers to object here}}
145 X<a2> x2;
146 X<a3> x3;
147 // cxx98-error@-1 {{non-type template argument referring to object 'a3' with internal linkage is a C++11 extension}}
148 // cxx98-note@#cwg112-a3 {{non-type template argument refers to object here}}
149 X<a4> x4;
150 }
151
152 namespace cwg113 { // cwg113: yes
153 extern void (*p)();
154 void f() {
155 no_such_function();
156 // expected-error@-1 {{use of undeclared identifier 'no_such_function'}}
157 p();
158 }
159 void g();
160 void (*p)() = &g;
161 }
162
163 namespace cwg114 { // cwg114: yes
164 struct A {
165 virtual void f(int) = 0; // #cwg114-A-f
166 };
167 struct B : A {
168 template<typename T> void f(T);
169 void g() { f(0); }
170 } b;
171 // expected-error@-1 {{variable type 'struct B' is an abstract class}}
172 // expected-note@#cwg114-A-f {{unimplemented pure virtual method 'f' in 'B'}}
173 }
174
175 namespace cwg115 { // cwg115: 3.0
176 template<typename T> int f(T); // #cwg115-f
177 template<typename T> int g(T); // #cwg115-g
178 template<typename T> int g(T, int); // #cwg115-g-int
179
180 int k1 = f(&f);
181 // expected-error@-1 {{no matching function for call to 'f'}}
182 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
183 int k2 = f(&f<int>);
184 int k3 = f(&g<int>);
185 // expected-error@-1 {{no matching function for call to 'f'}}
186 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
187
188 void h() {
189 (void)&f;
190 // expected-error@-1 {{address of overloaded function 'f' cannot be cast to type 'void'}}
191 // expected-note@#cwg115-f {{candidate function template}}
192 (void)&f<int>;
193 (void)&g<int>;
194 // expected-error@-1 {{address of overloaded function 'g' cannot be cast to type 'void'}}
195 // expected-note@#cwg115-g-int {{candidate function template}}
196 // expected-note@#cwg115-g {{candidate function template}}
197
198 &f;
199 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
200 // expected-note@#cwg115-f {{possible target for call}}
201 &f<int>;
202 // expected-warning@-1 {{expression result unused}}
203 &g<int>;
204 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
205 // expected-note@#cwg115-g-int {{possible target for call}}
206 // expected-note@#cwg115-g {{possible target for call}}
207 }
208
209 struct S {
210 template<typename T> static int f(T);
211 template<typename T> static int g(T);
212 template<typename T> static int g(T, int);
213 } s;
214
215 int k4 = f(&s.f);
216 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
217 int k5 = f(&s.f<int>);
218 int k6 = f(&s.g<int>);
219 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
220
221 void i() {
222 (void)&s.f;
223 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
224 (void)&s.f<int>;
225 (void)&s.g<int>;
226 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
227
228 &s.f;
229 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
230 &s.f<int>;
231 // expected-warning@-1 {{expression result unused}}
232 &s.g<int>;
233 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
234 }
235
236 struct T {
237 template<typename T> int f(T);
238 template<typename T> int g(T);
239 template<typename T> int g(T, int);
240 } t;
241
242 int k7 = f(&s.f);
243 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
244 int k8 = f(&s.f<int>);
245 int k9 = f(&s.g<int>);
246 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
247
248 void j() {
249 (void)&s.f;
250 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
251 (void)&s.f<int>;
252 (void)&s.g<int>;
253 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
254
255 &s.f;
256 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
257 &s.f<int>;
258 // expected-warning@-1 {{expression result unused}}
259 &s.g<int>;
260 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
261 }
262
263 #if __cplusplus >= 201103L
264 // Special case kicks in only if a template argument list is specified.
265 template<typename T=int> void with_default(); // #cwg115-with-default
266 int k10 = f(&with_default);
267 // expected-error@-1 {{no matching function for call to 'f'}}
268 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
269 int k11 = f(&with_default<>);
270 void k() {
271 (void)&with_default;
272 // expected-error@-1 {{address of overloaded function 'with_default' cannot be cast to type 'void'}}
273 // expected-note@#cwg115-with-default {{candidate function template}}
274 (void)&with_default<>;
275 &with_default;
276 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
277 // expected-note@#cwg115-with-default {{possible target for call}}
278 &with_default<>;
279 // expected-warning@-1 {{expression result unused}}
280 }
281 #endif
282 }
283
284 namespace cwg116 { // cwg116: yes
285 template<int> struct A {};
286 template<int N> void f(A<N>) {} // #cwg116-f-N
287 template<int M> void f(A<M>) {}
288 // expected-error@-1 {{redefinition of 'f'}}
289 // expected-note@#cwg116-f-N {{previous definition is here}}
290 template<typename T> void f(A<sizeof(T)>) {} // #cwg116-f-T
291 template<typename U> void f(A<sizeof(U)>) {}
292 // expected-error@-1 {{redefinition of 'f'}}
293 // expected-note@#cwg116-f-T {{previous definition is here}}
294 }
295
296 // cwg117: na
297 // cwg118 is in cwg118.cpp
298 // cwg119: na
299 // cwg120: na
300
301 namespace cwg121 { // cwg121: yes
302 struct X {
303 template<typename T> struct Y {};
304 };
305 template<typename T> struct Z {
306 X::Y<T> x;
307 T::Y<T> y;
308 // expected-error@-1 {{use 'template' keyword to treat 'Y' as a dependent template name}}
309 // cxx98-17-error@-2 {{missing 'typename' prior to dependent type name T::Y; implicit 'typename' is a C++20 extension}}
310 };
311 Z<X> z;
312 }
313
314 namespace cwg122 { // cwg122: yes
315 template<typename T> void f();
316 void g() { f<int>(); }
317 }
318
319 // cwg123: na
320 // cwg124 is in cwg124.cpp
321
322 // cwg125: yes
323 struct cwg125_A { struct cwg125_B {}; }; // #cwg125_B
324 cwg125_A::cwg125_B cwg125_C();
325 namespace cwg125_B { cwg125_A cwg125_C(); }
326 namespace cwg125 {
327 struct X {
328 friend cwg125_A::cwg125_B (::cwg125_C)(); // ok
329 friend cwg125_A (::cwg125_B::cwg125_C)(); // ok
330 friend cwg125_A::cwg125_B::cwg125_C(); // #cwg125_C
331 // expected-error@#cwg125_C {{missing return type for function 'cwg125_C'; did you mean the constructor name 'cwg125_B'?}}
332 // cxx98-error@#cwg125_C {{'cwg125_B' is missing exception specification 'throw()'}}
333 // cxx98-note@#cwg125_B {{previous declaration is here}}
334 // since-cxx11-error@#cwg125_C {{'cwg125_B' is missing exception specification 'noexcept'}}
335 // since-cxx11-note@#cwg125_B {{previous declaration is here}}
336 };
337 }
338
339 namespace cwg126 { // cwg126: partial
340 // FIXME: We do not yet generate correct code for this change:
341 // eg:
342 // catch (void*&) should catch void* but not int*
343 // catch (void*) and catch (void*const&) should catch both
344 // Likewise:
345 // catch (Base *&) should catch Base* but not Derived*
346 // catch (Base *) should catch both
347 // In each case, we emit the same code for both catches.
348 //
349 // The ABI does not let us represent the language rule in the unwind tables.
350 // So, when catching by non-const (or volatile) reference to pointer, we
351 // should compare the exception type to the caught type and only accept an
352 // exact match.
353 struct C {};
354 struct D : C {};
355 struct E : private C { friend class A; friend class B; };
356 struct F : protected C {};
357 struct G : C {};
358 struct H : D, G {};
359
360 #if __cplusplus <= 201402L
361 struct A {
362 virtual void cp() throw(C*);
363 virtual void dp() throw(C*);
364 virtual void ep() throw(C*); // #cwg126-ep
365 virtual void fp() throw(C*); // #cwg126-fp
366 virtual void gp() throw(C*);
367 virtual void hp() throw(C*); // #cwg126-hp
368
369 virtual void cr() throw(C&);
370 virtual void dr() throw(C&);
371 virtual void er() throw(C&); // #cwg126-er
372 virtual void fr() throw(C&); // #cwg126-fr
373 virtual void gr() throw(C&);
374 virtual void hr() throw(C&); // #cwg126-hr
375
376 virtual void pv() throw(void*);
377
378 virtual void np() throw(C*);
379 virtual void npm() throw(int C::*);
380 virtual void nr() throw(C*&); // #cwg126-nr
381 virtual void ncr() throw(C*const&);
382
383 virtual void ref1() throw(C *const&);
384 virtual void ref2() throw(C *);
385
386 virtual void v() throw(int);
387 virtual void w() throw(const int);
388 virtual void x() throw(int*); // #cwg126-x
389 virtual void y() throw(const int*);
390 virtual void z() throw(int); // #cwg126-z
391 };
392 struct B : A {
393 virtual void cp() throw(C*);
394 virtual void dp() throw(D*);
395 virtual void ep() throw(E*);
396 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
397 // cxx98-14-note@#cwg126-ep {{overridden virtual function is here}}
398 virtual void fp() throw(F*);
399 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
400 // cxx98-14-note@#cwg126-fp {{overridden virtual function is here}}
401 virtual void gp() throw(G*);
402 virtual void hp() throw(H*);
403 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
404 // cxx98-14-note@#cwg126-hp {{overridden virtual function is here}}
405
406 virtual void cr() throw(C&);
407 virtual void dr() throw(D&);
408 virtual void er() throw(E&);
409 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
410 // cxx98-14-note@#cwg126-er {{overridden virtual function is here}}
411 virtual void fr() throw(F&);
412 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
413 // cxx98-14-note@#cwg126-fr {{overridden virtual function is here}}
414 virtual void gr() throw(G&);
415 virtual void hr() throw(H&);
416 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
417 // cxx98-14-note@#cwg126-hr {{overridden virtual function is here}}
418
419 virtual void pv() throw(C*);
420
421 #if __cplusplus >= 201103L
422 using nullptr_t = decltype(nullptr);
423 virtual void np() throw(nullptr_t);
424 virtual void npm() throw(nullptr_t&);
425 virtual void nr() throw(nullptr_t);
426 // cxx11-14-error@-1 {{exception specification of overriding function is more lax than base version}}
427 // cxx11-14-note@#cwg126-nr {{overridden virtual function is here}}
428 virtual void ncr() throw(nullptr_t);
429 #endif // __cplusplus >= 201103L
430
431 virtual void ref1() throw(D *const &);
432 virtual void ref2() throw(D *);
433
434 virtual void v() throw(const int);
435 virtual void w() throw(int);
436 virtual void x() throw(const int*);
437 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
438 // cxx98-14-note@#cwg126-x {{overridden virtual function is here}}
439 virtual void y() throw(int*); // ok
440 virtual void z() throw(long);
441 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
442 // cxx98-14-note@#cwg126-z {{overridden virtual function is here}}
443 };
444 #endif // __cplusplus <= 201402L
445 void f() throw(int);
446 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
447 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
448 }
449
450 namespace cwg127 { // cwg127: 2.9
451 __extension__ typedef __decltype(sizeof(0)) size_t;
452 template<typename T> struct A {
453 A() { throw 0; }
454 void *operator new(size_t, const char * = 0);
455 void operator delete(void *, const char *) { T::error; } // #cwg127-delete-const-char
456 // expected-error@#cwg127-delete-const-char {{type 'void' cannot be used prior to '::' because it has no members}}
457 // expected-note@#cwg127-p {{in instantiation of member function 'cwg127::A<void>::operator delete' requested here}}
458 // expected-error@#cwg127-delete-const-char {{type 'int' cannot be used prior to '::' because it has no members}}
459 // expected-note@#cwg127-q {{in instantiation of member function 'cwg127::A<int>::operator delete' requested here}}
460 void operator delete(void *) { T::error; }
461 };
462 A<void> *p = new A<void>; // #cwg127-p
463 A<int> *q = new ("") A<int>; // #cwg127-q
464 }
465
466 namespace cwg128 { // cwg128: yes
467 enum E1 { e1 } x = e1;
468 enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1);
469 }
470
471 // cwg129: dup 616
472 // cwg130: na
473
474 namespace cwg131 { // cwg131: sup P1949
475 const char *a_with_\u0e8c = "\u0e8c";
476 const char *b_with_\u0e8d = "\u0e8d";
477 const char *c_with_\u0e8e = "\u0e8e";
478 }
479
480 namespace cwg132 { // cwg132: no
481 void f() {
482 extern struct {} x; // ok
483 extern struct S {} y; // FIXME: This is invalid.
484 }
485 static enum { E } e;
486 }
487
488 // cwg133: dup 87
489 // cwg134: na
490
491 namespace cwg135 { // cwg135: yes
492 struct A {
493 A f(A a) { return a; }
494 friend A g(A a) { return a; }
495 static A h(A a) { return a; }
496 };
497 }
498
499 namespace cwg136 { // cwg136: 3.4
500 void f(int, int, int = 0); // #cwg136-f
501 void g(int, int, int); // #cwg136-g
502 struct A {
503 friend void f(int, int = 0, int);
504 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
505 // expected-note@#cwg136-f {{previous declaration is here}}
506 friend void g(int, int, int = 0);
507 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
508 // expected-note@#cwg136-g {{previous declaration is here}}
509 friend void h(int, int, int = 0);
510 // expected-error@-1 {{friend declaration specifying a default argument must be a definition}}
511 friend void i(int, int, int = 0) {} // #cwg136-A-i
512 friend void j(int, int, int = 0) {}
513 operator int();
514 };
515 void i(int, int, int);
516 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
517 // expected-note@#cwg136-A-i {{previous declaration is here}}
518 void q() {
519 j(A(), A()); // ok, has default argument
520 }
521 extern "C" void k(int, int, int, int); // #cwg136-k
522 namespace NSA {
523 struct A {
524 friend void cwg136::k(int, int, int, int = 0);
525 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
526 // expected-note@#cwg136-k {{previous declaration is here}}
527 };
528 }
529 namespace NSB {
530 struct A {
531 friend void cwg136::k(int, int, int = 0, int); // #cwg136-friend-k
532 // expected-error@#cwg136-friend-k {{friend declaration specifying a default argument must be the only declaration}}
533 // expected-note@#cwg136-k {{previous declaration is here}}
534 // expected-error@#cwg136-friend-k {{missing default argument on parameter}}
535 };
536 }
537 struct B {
538 void f(int); // #cwg136-B-f
539 };
540 struct C {
541 friend void B::f(int = 0);
542 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
543 // expected-note@#cwg136-B-f {{previous declaration is here}}
544 };
545 }
546
547 namespace cwg137 { // cwg137: yes
548 extern void *p;
549 extern const void *cp;
550 extern volatile void *vp;
551 extern const volatile void *cvp;
552 int *q = static_cast<int*>(p);
553 int *qc = static_cast<int*>(cp);
554 // expected-error@-1 {{static_cast from 'const void *' to 'int *' casts away qualifiers}}
555 int *qv = static_cast<int*>(vp);
556 // expected-error@-1 {{static_cast from 'volatile void *' to 'int *' casts away qualifiers}}
557 int *qcv = static_cast<int*>(cvp);
558 // expected-error@-1 {{static_cast from 'const volatile void *' to 'int *' casts away qualifiers}}
559 const int *cq = static_cast<const int*>(p);
560 const int *cqc = static_cast<const int*>(cp);
561 const int *cqv = static_cast<const int*>(vp);
562 // expected-error@-1 {{static_cast from 'volatile void *' to 'const int *' casts away qualifiers}}
563 const int *cqcv = static_cast<const int*>(cvp);
564 // expected-error@-1 {{static_cast from 'const volatile void *' to 'const int *' casts away qualifiers}}
565 const volatile int *cvq = static_cast<const volatile int*>(p);
566 const volatile int *cvqc = static_cast<const volatile int*>(cp);
567 const volatile int *cvqv = static_cast<const volatile int*>(vp);
568 const volatile int *cvqcv = static_cast<const volatile int*>(cvp);
569 }
570
571 namespace cwg139 { // cwg139: yes
572 namespace example1 {
573 typedef int f; // #cwg139-typedef-f
574 struct A {
575 friend void f(A &);
576 // expected-error@-1 {{redefinition of 'f' as different kind of symbol}}
577 // expected-note@#cwg139-typedef-f {{previous definition is here}}
578 };
579 }
580
581 namespace example2 {
582 typedef int f;
583 namespace N {
584 struct A {
585 friend void f(A &);
586 operator int();
587 void g(A a) { int i = f(a); } // ok, f is typedef not friend function
588 };
589 }
590 }
591 }
592
593 namespace cwg140 { // cwg140: yes
594 void f(int *const) {} // #cwg140-f-first
595 void f(int[3]) {}
596 // expected-error@-1 {{redefinition of 'f'}}
597 // expected-note@#cwg140-f-first {{previous definition is here}}
598 void g(const int);
599 void g(int n) { n = 2; }
600 }
601
602 namespace cwg141 { // cwg141: 3.1
603 template<typename T> void f();
604 template<typename T> struct S { int n; }; // #cwg141-S
605 struct A : S<int> {
606 template<typename T> void f();
607 template<typename T> struct S {}; // #cwg141-A-S
608 } a;
609 struct B : S<int> {} b;
610 void g() {
611 a.f<int>();
612 (void)a.S<int>::n; // #cwg141-a
613 // cxx98-error@#cwg141-a {{lookup of 'S' in member access expression is ambiguous; using member of 'struct A'}}
614 // cxx98-note@#cwg141-A-S {{lookup in the object type 'struct A' refers here}}
615 // cxx98-note@#cwg141-S {{lookup from the current scope refers here}}
616 // expected-error@#cwg141-a {{no member named 'n' in 'cwg141::A::S<int>'; did you mean '::cwg141::S<int>::n'?}}
617 // expected-note@#cwg141-S {{'::cwg141::S<int>::n' declared here}}
618 // FIXME: we issue a useful diagnostic first, then some bogus ones.
619 b.f<int>();
620 // expected-error@-1 {{no member named 'f' in 'cwg141::B'}}
621 // expected-error@-2 +{{}}
622 (void)b.S<int>::n;
623 }
624 template<typename T> struct C {
625 T t;
626 void g() {
627 t.f<int>();
628 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}
629 }
630 void h() {
631 (void)t.S<int>::n; // ok
632 }
633 void i() {
634 (void)t.S<int>(); // ok!
635 }
636 };
637 void h() { C<B>().h(); } // ok
638 struct X {
639 template<typename T> void S();
640 };
641 void i() { C<X>().i(); } // ok!!
642 }
643
644 namespace cwg142 { // cwg142: 2.8
645 class B { // #cwg142-B
646 public:
647 int mi; // #cwg142-B-mi
648 static int si; // #cwg142-B-si
649 };
650 class D : private B { // #cwg142-D
651 };
652 class DD : public D {
653 void f();
654 };
655 void DD::f() {
656 mi = 3;
657 // expected-error@-1 {{'mi' is a private member of 'cwg142::B'}}
658 // expected-note@#cwg142-D {{constrained by private inheritance here}}
659 // expected-note@#cwg142-B-mi {{member is declared here}}
660 si = 3;
661 // expected-error@-1 {{'si' is a private member of 'cwg142::B'}}
662 // expected-note@#cwg142-D {{constrained by private inheritance here}}
663 // expected-note@#cwg142-B-si {{member is declared here}}
664 B b_old;
665 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}}
666 // expected-note@#cwg142-D {{constrained by private inheritance here}}
667 // expected-note@#cwg142-B {{member is declared here}}
668 cwg142::B b;
669 b.mi = 3;
670 b.si = 3;
671 B::si = 3;
672 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}}
673 // expected-note@#cwg142-D {{constrained by private inheritance here}}
674 // expected-note@#cwg142-B {{member is declared here}}
675 cwg142::B::si = 3;
676 B *bp1_old = this; // #cwg142-bp1_old
677 // expected-error@#cwg142-bp1_old {{'B' is a private member of 'cwg142::B'}}
678 // expected-note@#cwg142-D {{constrained by private inheritance here}}
679 // expected-note@#cwg142-B {{member is declared here}}
680 // expected-error@#cwg142-bp1_old {{cannot cast 'cwg142::DD' to its private base class 'B'}}
681 // expected-note@#cwg142-D {{declared private here}}
682 cwg142::B *bp1 = this;
683 // expected-error@-1 {{cannot cast 'cwg142::DD' to its private base class 'cwg142::B'}}
684 // expected-note@#cwg142-D {{declared private here}}
685 B *bp2_old = (B*)this; // #cwg142-bp2_old
686 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}}
687 // expected-note@#cwg142-D {{constrained by private inheritance here}}
688 // expected-note@#cwg142-B {{member is declared here}}
689 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}}
690 // expected-note@#cwg142-D {{constrained by private inheritance here}}
691 // expected-note@#cwg142-B {{member is declared here}}
692 cwg142::B *bp2 = (cwg142::B*)this;
693 bp2->mi = 3;
694 }
695 }
696
697 namespace cwg143 { // cwg143: yes
698 namespace A { struct X; }
699 namespace B { void f(A::X); }
700 namespace A {
701 struct X { friend void B::f(X); };
702 }
703 void g(A::X x) {
704 f(x);
705 // expected-error@-1 {{use of undeclared identifier 'f'}}
706 }
707 }
708
709 namespace cwg145 { // cwg145: yes
710 void f(bool b) {
711 ++b;
712 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}}
713 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
714 b++;
715 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}}
716 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
717 }
718 }
719
720 namespace cwg147 { // cwg147: yes
721 namespace example1 {
722 template<typename> struct A {
723 template<typename T> A(T);
724 };
725 // Per core issue 1435, this is ill-formed because A<int>::A<int> does not
726 // name the injected-class-name. (A<int>::A does, though.)
727 template<> template<> A<int>::A<int>(int) {}
728 // expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}}
729 template<> template<> A<float>::A(float) {}
730 }
731 namespace example2 {
732 struct A { A(); };
733 struct B : A { B(); };
734 A::A a1;
735 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a type in this context}}
736 B::A a2;
737 }
738 namespace example3 {
739 template<typename> struct A {
740 template<typename T> A(T);
741 static A a;
742 };
743 template<> A<int>::A<int>(A<int>::a);
744 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a template name in this context}}
745 }
746 }
747
748 namespace cwg148 { // cwg148: yes
749 struct A { int A::*p; };
750 static_assert(__is_pod(int(A::*)), "");
751 static_assert(__is_pod(A), "");
752 }
753
754 // cwg149: na
755
756 namespace cwg150 { // cwg150: 19
757 namespace p1 {
758 template <class T, class U = int>
759 class ARG { };
760
761 template <class X, template <class Y> class PARM>
762 void f(PARM<X>) { }
763
764 void g() {
765 ARG<int> x;
766 f(x);
767 }
768 } // namespace p1
769
770 namespace p2 {
771 template <template <class T, class U = int> class PARM>
772 class C {
773 PARM<int> pi;
774 };
775 } // namespace p2
776
777 namespace n1 {
778 struct Dense { static const unsigned int dim = 1; };
779
780 template <template <typename> class View,
781 typename Block>
782 void operator+(float, View<Block> const&);
783
784 template <typename Block,
785 unsigned int Dim = Block::dim>
786 class Lvalue_proxy { operator float() const; };
787
788 void test_1d (void) {
789 Lvalue_proxy<Dense> p;
790 float b;
791 b + p;
792 }
793 } // namespace n1
794 }
795
796 namespace cwg151 { // cwg151: 3.1
797 struct X {};
798 typedef int X::*p;
799 static_assert(__enable_constant_folding(p() == 0), "");
800 }
801
802 namespace cwg152 { // cwg152: yes
803 struct A {
804 A(); // #cwg152-A-ctor
805 explicit A(const A&); // #cwg152-A-explicit-ctor
806 };
807 A a1 = A();
808 // cxx98-14-error@-1 {{no matching constructor for initialization of 'A'}}
809 // cxx98-14-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}}
810 // cxx98-14-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
811 A a2((A()));
812
813 A &f();
814 A a3 = f();
815 // expected-error@-1 {{no matching constructor for initialization of 'A'}}
816 // expected-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}}
817 // expected-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
818 A a4(f());
819 }
820
821 // cwg153: na
822
823 namespace cwg154 { // cwg154: yes
824 union { int a; };
825 // expected-error@-1 {{nonymous unions at namespace or global scope must be declared 'static'}}
826 namespace {
827 union { int b; };
828 }
829 static union { int c; };
830 }
831
832 namespace cwg155 { // cwg155: dup 632
833 struct S { int n; } s = { { 1 } };
834 // expected-warning@-1 {{braces around scalar initializer}}
835 }
836
837 // cwg158 is in cwg158.cpp
838
839 namespace cwg159 { // cwg159: 3.5
840 namespace X { void f(); }
841 void f();
842 void cwg159::f() {}
843 // expected-warning@-1 {{extra qualification on member 'f'}}
844 void cwg159::X::f() {}
845 }
846
847 // cwg160: na
848
849 namespace cwg161 { // cwg161: 3.1
850 class A {
851 protected:
852 struct B { int n; } b; // #cwg161-B
853 static B bs;
854 void f(); // #cwg161-f
855 static void sf();
856 };
857 struct C : A {};
858 struct D : A {
859 void g(C c) {
860 (void)b.n;
861 B b1;
862 C::B b2; // ok, accessible as a member of A
863 (void)&C::b;
864 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}
865 // expected-note@#cwg161-B {{declared protected here}}
866 (void)&C::bs;
867 (void)c.b;
868 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}
869 // expected-note@#cwg161-B {{declared protected here}}
870 (void)c.bs;
871 f();
872 sf();
873 c.f();
874 // expected-error@-1 {{protected}}
875 // expected-note@#cwg161-f {{declared protected here}}
876 c.sf();
877 A::f();
878 D::f();
879 A::sf();
880 C::sf();
881 D::sf();
882 }
883 };
884 }
885
886 namespace cwg162 { // cwg162: 19
887 struct A {
888 char &f(char);
889 static int &f(int);
890
891 void g() {
892 int &a = (&A::f)(0);
893 char &b = (&A::f)('0');
894 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
895 }
896 };
897
898 int &c = (&A::f)(0);
899 char &d = (&A::f)('0');
900 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
901 }
902
903 // cwg163: na
904
905 namespace cwg164 { // cwg164: yes
906 void f(int);
907 template <class T> int g(T t) { return f(t); }
908
909 enum E { e };
910 int f(E);
911
912 int k = g(e);
913 }
914
915 namespace cwg165 { // cwg165: no
916 namespace N {
917 struct A { friend struct B; };
918 void f() { void g(); }
919 }
920 // FIXME: cwg1477 says this is ok, cwg165 says it's ill-formed
921 struct N::B {};
922 // FIXME: cwg165 says this is ill-formed, but the argument in cwg1477 says it's ok
923 void N::g() {}
924 }
925
926 namespace cwg166 { // cwg166: 2.9
927 namespace A { class X; }
928
929 template<typename T> int f(T t) { return t.n; }
930 int g(A::X);
931 template<typename T> int h(T t) { return t.n; }
932 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}
933 // expected-note@#cwg166-h-instantiation {{in instantiation of function template specialization 'cwg166::h<cwg166::A::X>' requested here}}
934 // expected-note@#cwg166-X-n {{implicitly declared private here}}
935 int i(A::X);
936
937 namespace A {
938 class X {
939 friend int f<X>(X);
940 friend int cwg166::g(X);
941 friend int h(X);
942 friend int i(X);
943 int n; // #cwg166-X-n
944 };
945
946 int h(X x) { return x.n; }
947 int i(X x) { return x.n; }
948 }
949
950 template int f(A::X);
951 int g(A::X x) { return x.n; }
952 template int h(A::X); // #cwg166-h-instantiation
953 int i(A::X x) { return x.n; }
954 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}
955 // expected-note@#cwg166-X-n {{implicitly declared private here}}
956 }
957
958 // cwg167: sup 1012
959
960 namespace cwg168 { // cwg168: no
961 extern "C" typedef int (*p)();
962 extern "C++" typedef int (*q)();
963 struct S {
964 static int f();
965 };
966 p a = &S::f; // FIXME: this should fail.
967 q b = &S::f;
968 }
969
970 namespace cwg169 { // cwg169: yes
971 template<typename> struct A { int n; };
972 struct B {
973 template<typename> struct C;
974 template<typename> void f();
975 template<typename> static int n;
976 // cxx98-11-error@-1 {{variable templates are a C++14 extension}}
977 };
978 struct D : A<int>, B {
979 using A<int>::n;
980 using B::C<int>;
981 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
982 using B::f<int>;
983 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
984 using B::n<int>;
985 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
986 };
987 }
988
989 namespace { // cwg171: 3.4
990 int cwg171a;
991 }
992 int cwg171b; // #cwg171b-int
993 namespace cwg171 {
994 extern "C" void cwg171a();
995 extern "C" void cwg171b();
996 // expected-error@-1 {{declaration of 'cwg171b' with C language linkage conflicts with declaration in global scope}}
997 // expected-note@#cwg171b-int {{declared in global scope here}}
998 }
999
1000 namespace cwg172 { // cwg172: yes
1001 enum { zero };
1002 static_assert(-1 < zero, "");
1003
1004 enum { x = -1, y = (unsigned int)-1 };
1005 static_assert(sizeof(x) > sizeof(int), "");
1006
1007 enum { a = (unsigned int)-1 / 2 };
1008 static_assert(sizeof(a) == sizeof(int), "");
1009 static_assert(-a < 0, "");
1010
1011 enum { b = (unsigned int)-1 / 2 + 1 };
1012 static_assert(sizeof(b) == sizeof(unsigned int), "");
1013 static_assert(-b > 0, "");
1014
1015 enum { c = (unsigned long)-1 / 2 };
1016 static_assert(sizeof(c) == sizeof(long), "");
1017 static_assert(-c < 0, "");
1018
1019 enum { d = (unsigned long)-1 / 2 + 1 };
1020 static_assert(sizeof(d) == sizeof(unsigned long), "");
1021 static_assert(-d > 0, "");
1022
1023 enum { e = (unsigned long long)-1 / 2 };
1024 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1025 static_assert(sizeof(e) == sizeof(long), "");
1026 static_assert(-e < 0, "");
1027
1028 enum { f = (unsigned long long)-1 / 2 + 1 };
1029 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1030 static_assert(sizeof(f) == sizeof(unsigned long), "");
1031 static_assert(-f > 0, "");
1032 }
1033
1034 namespace cwg173 { // cwg173: yes
1035 static_assert('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&
1036 '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&
1037 '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9', "");
1038 }
1039
1040 // cwg174: sup 1012
1041
1042 namespace cwg175 { // cwg175: 2.8
1043 struct A {}; // #cwg175-A
1044 struct B : private A {}; // #cwg175-B
1045 struct C : B {
1046 A a;
1047 // expected-error@-1 {{'A' is a private member of 'cwg175::A'}}
1048 // expected-note@#cwg175-B {{constrained by private inheritance here}}
1049 // expected-note@#cwg175-A {{member is declared here}}
1050 cwg175::A b;
1051 };
1052 }
1053
1054 namespace cwg176 { // cwg176: 3.1
1055 template<typename T> class Y;
1056 template<> class Y<int> {
1057 void f() {
1058 typedef Y A; // #cwg176-A-first
1059 typedef Y<char> A;
1060 // expected-error@-1 {{typedef redefinition with different types ('Y<char>' vs 'Y<int>')}}
1061 // expected-note@#cwg176-A-first {{previous definition is here}}
1062 }
1063 };
1064
1065 template<typename T> struct Base {}; // #cwg176-Base
1066 template<typename T> struct Derived : public Base<T> {
1067 void f() {
1068 typedef typename Derived::template Base<T> A;
1069 typedef typename Derived::Base A;
1070 }
1071 };
1072 template struct Derived<int>;
1073
1074 template<typename T> struct Derived2 : Base<int>, Base<char> {
1075 typename Derived2::Base b;
1076 // expected-error@-1 {{member 'Base' found in multiple base classes of different types}}
1077 // expected-note@#cwg176-Base {{member type 'cwg176::Base<int>' found by ambiguous name lookup}}
1078 // expected-note@#cwg176-Base {{member type 'cwg176::Base<char>' found by ambiguous name lookup}}
1079 typename Derived2::Base<double> d;
1080 };
1081
1082 template<typename T> class X { // #cwg176-X
1083 X *p1;
1084 X<T> *p2;
1085 X<int> *p3;
1086 cwg176::X *p4; // #cwg176-p4
1087 // cxx98-14-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments}}
1088 // cxx98-14-note@#cwg176-X {{template is declared here}}
1089 // since-cxx17-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments; argument deduction not allowed in non-static class member}}
1090 // since-cxx17-note@#cwg176-X {{template is declared here}}
1091 };
1092 }
1093
1094 namespace cwg177 { // cwg177: yes
1095 struct B {};
1096 struct A {
1097 A(A &); // #cwg177-A-copy-ctor
1098 A(const B &); // #cwg177-A-ctor-from-B
1099 };
1100 B b;
1101 A a = b;
1102 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'A'}}
1103 // cxx98-14-note@#cwg177-A-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1104 // cxx98-14-note@#cwg177-A-ctor-from-B {{candidate constructor not viable: no known conversion from 'A' to 'const B &' for 1st argument}}
1105
1106 struct C { C(C&); }; // #cwg177-C-copy-ctor
1107 struct D : C {};
1108 struct E { operator D(); };
1109 E e;
1110 C c = e;
1111 // expected-error@-1 {{no viable constructor copying variable of type 'D'}}
1112 // expected-note@#cwg177-C-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1113 }
1114
1115 namespace cwg178 { // cwg178: yes
1116 static_assert(int() == 0, "");
1117 #if __cplusplus >= 201103L
1118 static_assert(int{} == 0, "");
1119 struct S { int a, b; };
1120 static_assert(S{1}.b == 0, "");
1121 struct T { constexpr T() : n() {} int n; };
1122 static_assert(T().n == 0, "");
1123 struct U : S { constexpr U() : S() {} };
1124 static_assert(U().b == 0, "");
1125 #endif
1126 }
1127
1128 namespace cwg179 { // cwg179: yes
1129 void f();
1130 int n = &f - &f;
1131 // expected-error@-1 {{arithmetic on pointers to the function type 'void ()'}}
1132 }
1133
1134 namespace cwg180 { // cwg180: 2.8
1135 template<typename T> struct X : T, T::some_base {
1136 X() : T::some_type_that_might_be_T(), T::some_base() {}
1137 friend class T::some_class;
1138 void f() {
1139 enum T::some_enum e;
1140 }
1141 };
1142 }
1143
1144 namespace cwg181 { // cwg181: yes
1145 namespace X {
1146 template <template X<class T> > struct A { };
1147 // expected-error@-1 +{{}}
1148 template <template X<class T> > void f(A<X>) { }
1149 // expected-error@-1 +{{}}
1150 }
1151
1152 namespace Y {
1153 template <template <class T> class X> struct A { };
1154 template <template <class T> class X> void f(A<X>) { }
1155 }
1156 }
1157
1158 namespace cwg182 { // cwg182: 14
1159 template <class T> struct C {
1160 void f();
1161 void g();
1162 };
1163
1164 template <class T> void C<T>::f() {}
1165 template <class T> void C<T>::g() {}
1166
1167 class A {
1168 class B {};
1169 void f();
1170 };
1171
1172 template void C<A::B>::f();
1173 template <> void C<A::B>::g();
1174
1175 void A::f() {
1176 C<B> cb;
1177 cb.f();
1178 }
1179 }
1180
1181 namespace cwg183 { // cwg183: sup 382
1182 template<typename T> struct A {};
1183 template<typename T> struct B {
1184 typedef int X;
1185 };
1186 template<> struct A<int> {
1187 typename B<int>::X x;
1188 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1189 };
1190 }
1191
1192 namespace cwg184 { // cwg184: yes
1193 template<typename T = float> struct B {};
1194
1195 template<template<typename TT = float> class T> struct A {
1196 void f();
1197 void g();
1198 };
1199
1200 template<template<typename TT> class T> void A<T>::f() { // #cwg184-T
1201 T<> t;
1202 // expected-error@-1 {{too few template arguments for template template parameter 'T'}}
1203 // expected-note@#cwg184-T {{template is declared here}}
1204 }
1205
1206 template<template<typename TT = char> class T> void A<T>::g() {
1207 T<> t;
1208 typedef T<> X;
1209 typedef T<char> X;
1210 }
1211
1212 void h() { A<B>().g(); }
1213 }
1214
1215 // cwg185 is in cwg185.cpp
1216
1217 namespace cwg187 { // cwg187: sup 481
1218 const int Z = 1;
1219 template<int X = Z, int Z = X> struct A;
1220 typedef A<> T;
1221 typedef A<1, 1> T;
1222 }
1223
1224 namespace cwg188 { // cwg188: yes
1225 char c[10];
1226 static_assert(sizeof(0, c) == 10, "");
1227 }
1228
1229 // cwg190 FIXME: add codegen test for tbaa
1230 // or implement C++20 std::is_layout_compatible and test it this way
1231
1232 int cwg191_j;
1233 namespace cwg191 { // cwg191: yes
1234 namespace example1 {
1235 struct outer {
1236 static int i;
1237 struct inner {
1238 void f() {
1239 struct local {
1240 void g() {
1241 i = 5;
1242 }
1243 };
1244 }
1245 };
1246 };
1247 }
1248
1249 namespace example2 {
1250 struct S {
1251 void f() {
1252 struct local2 {
1253 void g() {
1254 cwg191_j = 5;
1255 }
1256 };
1257 }
1258 };
1259 }
1260 }
1261
1262 // cwg193 is in cwg193.cpp
1263
1264 namespace cwg194 { // cwg194: yes
1265 struct A {
1266 A();
1267 void A();
1268 // expected-error@-1 {{constructor cannot have a return type}}
1269 };
1270 struct B {
1271 void B();
1272 // expected-error@-1 {{constructor cannot have a return type}}
1273 B();
1274 };
1275 struct C {
1276 inline explicit C(int) {}
1277 };
1278 }
1279
1280 namespace cwg195 { // cwg195: yes
1281 void f();
1282 int *p = (int*)&f;
1283 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}
1284 void (*q)() = (void(*)())&p;
1285 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}
1286 }
1287
1288 namespace cwg197 { // cwg197: yes
1289 char &f(char);
1290
1291 template <class T> void g(T t) {
1292 char &a = f(1);
1293 char &b = f(T(1));
1294 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
1295 // expected-note@#cwg197-g-e-call {{in instantiation of function template specialization 'cwg197::g<cwg197::E>' requested here}}
1296 char &c = f(t);
1297 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
1298 }
1299
1300 void f(int);
1301
1302 enum E { e };
1303 int &f(E);
1304
1305 void h() {
1306 g('a');
1307 g(2);
1308 g(e); // #cwg197-g-e-call
1309 }
1310 }
1311
1312 namespace cwg198 { // cwg198: yes
1313 struct A {
1314 int n;
1315 struct B {
1316 int m[sizeof(n)];
1317 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1318 int f() { return n; }
1319 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}
1320 };
1321 struct C;
1322 struct D;
1323 };
1324 struct A::C {
1325 int m[sizeof(n)];
1326 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1327 int f() { return n; }
1328 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}
1329 };
1330 struct A::D : A {
1331 int m[sizeof(n)];
1332 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1333 int f() { return n; }
1334 };
1335 }
1336
1337 // cwg199 is in cwg199.cpp