[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CXX / drs / cwg1xx.cpp
blob6aec8b65c91f12ac297c2bf57164d0d2e126b496
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
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
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
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}}
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;
49 using X::cwg101_f;
50 using X::size_t;
51 extern "C" void cwg101_f();
52 typedef unsigned size_t;
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'}}
62 namespace B {
63 struct S {};
65 B::S operator+(B::S, B::S); // #cwg102-operator-plus
66 template B::S A::f(B::S, B::S); // #cwg102-instantiation
69 // cwg103: na
70 // cwg104: na lib
71 // cwg105: na
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}}
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}}
89 namespace cwg107 { // cwg107: yes
90 struct S {};
91 extern "C" S operator+(S, S) { return S(); }
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'}}
102 template<> struct A<int>::B { int X; };
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}}
122 namespace cwg110 { // cwg110: 2.8
123 template <typename T>
124 void f(T);
126 class f {};
128 template <typename T>
129 void f(T, T);
131 class f g;
132 void (*h)(int) = static_cast<void(*)(int)>(f);
133 void (*i)(int, int) = static_cast<void(*)(int, int)>(f);
134 } // namespace cwg110
136 namespace cwg111 { // cwg111: dup 535
137 struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };
138 struct B : A { B(); }; // #cwg111-B
139 const B b1;
140 B b2(b1);
141 // expected-error@-1 {{no matching constructor for initialization of 'B'}}
142 // expected-note@#cwg111-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const B') would lose const qualifier}}
143 // expected-note@#cwg111-B {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
146 namespace cwg112 { // cwg112: yes
147 struct T { int n; };
148 typedef T Arr[1];
150 const T a1[1] = {}; // #cwg112-a1
151 volatile T a2[1] = {};
152 const Arr a3 = {}; // #cwg112-a3
153 volatile Arr a4 = {};
154 template<const volatile T*> struct X {};
155 // FIXME: Test this somehow in C++11 and on.
156 X<a1> x1;
157 // cxx98-error@-1 {{non-type template argument referring to object 'a1' with internal linkage is a C++11 extension}}
158 // cxx98-note@#cwg112-a1 {{non-type template argument refers to object here}}
159 X<a2> x2;
160 X<a3> x3;
161 // cxx98-error@-1 {{non-type template argument referring to object 'a3' with internal linkage is a C++11 extension}}
162 // cxx98-note@#cwg112-a3 {{non-type template argument refers to object here}}
163 X<a4> x4;
166 namespace cwg113 { // cwg113: yes
167 extern void (*p)();
168 void f() {
169 no_such_function();
170 // expected-error@-1 {{use of undeclared identifier 'no_such_function'}}
171 p();
173 void g();
174 void (*p)() = &g;
177 namespace cwg114 { // cwg114: yes
178 struct A {
179 virtual void f(int) = 0; // #cwg114-A-f
181 struct B : A {
182 template<typename T> void f(T);
183 void g() { f(0); }
184 } b;
185 // expected-error@-1 {{variable type 'struct B' is an abstract class}}
186 // expected-note@#cwg114-A-f {{unimplemented pure virtual method 'f' in 'B'}}
189 namespace cwg115 { // cwg115: 3.0
190 template<typename T> int f(T); // #cwg115-f
191 template<typename T> int g(T); // #cwg115-g
192 template<typename T> int g(T, int); // #cwg115-g-int
194 int k1 = f(&f);
195 // expected-error@-1 {{no matching function for call to 'f'}}
196 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
197 int k2 = f(&f<int>);
198 int k3 = f(&g<int>);
199 // expected-error@-1 {{no matching function for call to 'f'}}
200 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
202 void h() {
203 (void)&f;
204 // expected-error@-1 {{address of overloaded function 'f' cannot be cast to type 'void'}}
205 // expected-note@#cwg115-f {{candidate function template}}
206 (void)&f<int>;
207 (void)&g<int>;
208 // expected-error@-1 {{address of overloaded function 'g' cannot be cast to type 'void'}}
209 // expected-note@#cwg115-g-int {{candidate function template}}
210 // expected-note@#cwg115-g {{candidate function template}}
213 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
214 // expected-note@#cwg115-f {{possible target for call}}
215 &f<int>;
216 // expected-warning@-1 {{expression result unused}}
217 &g<int>;
218 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
219 // expected-note@#cwg115-g-int {{possible target for call}}
220 // expected-note@#cwg115-g {{possible target for call}}
223 struct S {
224 template<typename T> static int f(T);
225 template<typename T> static int g(T);
226 template<typename T> static int g(T, int);
227 } s;
229 int k4 = f(&s.f);
230 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
231 int k5 = f(&s.f<int>);
232 int k6 = f(&s.g<int>);
233 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
235 void i() {
236 (void)&s.f;
237 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
238 (void)&s.f<int>;
239 (void)&s.g<int>;
240 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
242 &s.f;
243 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
244 &s.f<int>;
245 // expected-warning@-1 {{expression result unused}}
246 &s.g<int>;
247 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
250 struct T {
251 template<typename T> int f(T);
252 template<typename T> int g(T);
253 template<typename T> int g(T, int);
254 } t;
256 int k7 = f(&s.f);
257 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
258 int k8 = f(&s.f<int>);
259 int k9 = f(&s.g<int>);
260 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
262 void j() {
263 (void)&s.f;
264 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
265 (void)&s.f<int>;
266 (void)&s.g<int>;
267 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
269 &s.f;
270 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
271 &s.f<int>;
272 // expected-warning@-1 {{expression result unused}}
273 &s.g<int>;
274 // expected-error@-1 {{cannot create a non-constant pointer to member function}}
277 #if __cplusplus >= 201103L
278 // Special case kicks in only if a template argument list is specified.
279 template<typename T=int> void with_default(); // #cwg115-with-default
280 int k10 = f(&with_default);
281 // expected-error@-1 {{no matching function for call to 'f'}}
282 // expected-note@#cwg115-f {{candidate template ignored: couldn't infer template argument 'T'}}
283 int k11 = f(&with_default<>);
284 void k() {
285 (void)&with_default;
286 // expected-error@-1 {{address of overloaded function 'with_default' cannot be cast to type 'void'}}
287 // expected-note@#cwg115-with-default {{candidate function template}}
288 (void)&with_default<>;
289 &with_default;
290 // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}}
291 // expected-note@#cwg115-with-default {{possible target for call}}
292 &with_default<>;
293 // expected-warning@-1 {{expression result unused}}
295 #endif
298 namespace cwg116 { // cwg116: yes
299 template<int> struct A {};
300 template<int N> void f(A<N>) {} // #cwg116-f-N
301 template<int M> void f(A<M>) {}
302 // expected-error@-1 {{redefinition of 'f'}}
303 // expected-note@#cwg116-f-N {{previous definition is here}}
304 template<typename T> void f(A<sizeof(T)>) {} // #cwg116-f-T
305 template<typename U> void f(A<sizeof(U)>) {}
306 // expected-error@-1 {{redefinition of 'f'}}
307 // expected-note@#cwg116-f-T {{previous definition is here}}
310 // cwg117: na
311 // cwg118 is in cwg118.cpp
312 // cwg119: na
313 // cwg120: na
315 namespace cwg121 { // cwg121: yes
316 struct X {
317 template<typename T> struct Y {};
319 template<typename T> struct Z {
320 X::Y<T> x;
321 T::Y<T> y;
322 // expected-error@-1 {{use 'template' keyword to treat 'Y' as a dependent template name}}
323 // cxx98-17-error@-2 {{missing 'typename' prior to dependent type name T::Y; implicit 'typename' is a C++20 extension}}
325 Z<X> z;
328 namespace cwg122 { // cwg122: yes
329 template<typename T> void f();
330 void g() { f<int>(); }
333 // cwg123: na
334 // cwg124 is in cwg124.cpp
336 // cwg125: yes
337 struct cwg125_A { struct cwg125_B {}; }; // #cwg125_B
338 cwg125_A::cwg125_B cwg125_C();
339 namespace cwg125_B { cwg125_A cwg125_C(); }
340 namespace cwg125 {
341 struct X {
342 friend cwg125_A::cwg125_B (::cwg125_C)(); // ok
343 friend cwg125_A (::cwg125_B::cwg125_C)(); // ok
344 friend cwg125_A::cwg125_B::cwg125_C(); // #cwg125_C
345 // expected-error@#cwg125_C {{missing return type for function 'cwg125_C'; did you mean the constructor name 'cwg125_B'?}}
346 // cxx98-error@#cwg125_C {{'cwg125_B' is missing exception specification 'throw()'}}
347 // cxx98-note@#cwg125_B {{previous declaration is here}}
348 // since-cxx11-error@#cwg125_C {{'cwg125_B' is missing exception specification 'noexcept'}}
349 // since-cxx11-note@#cwg125_B {{previous declaration is here}}
353 namespace cwg126 { // cwg126: partial
354 // FIXME: We do not yet generate correct code for this change:
355 // eg:
356 // catch (void*&) should catch void* but not int*
357 // catch (void*) and catch (void*const&) should catch both
358 // Likewise:
359 // catch (Base *&) should catch Base* but not Derived*
360 // catch (Base *) should catch both
361 // In each case, we emit the same code for both catches.
363 // The ABI does not let us represent the language rule in the unwind tables.
364 // So, when catching by non-const (or volatile) reference to pointer, we
365 // should compare the exception type to the caught type and only accept an
366 // exact match.
367 struct C {};
368 struct D : C {};
369 struct E : private C { friend class A; friend class B; };
370 struct F : protected C {};
371 struct G : C {};
372 struct H : D, G {};
374 #if __cplusplus <= 201402L
375 struct A {
376 virtual void cp() throw(C*);
377 virtual void dp() throw(C*);
378 virtual void ep() throw(C*); // #cwg126-ep
379 virtual void fp() throw(C*); // #cwg126-fp
380 virtual void gp() throw(C*);
381 virtual void hp() throw(C*); // #cwg126-hp
383 virtual void cr() throw(C&);
384 virtual void dr() throw(C&);
385 virtual void er() throw(C&); // #cwg126-er
386 virtual void fr() throw(C&); // #cwg126-fr
387 virtual void gr() throw(C&);
388 virtual void hr() throw(C&); // #cwg126-hr
390 virtual void pv() throw(void*);
392 virtual void np() throw(C*);
393 virtual void npm() throw(int C::*);
394 virtual void nr() throw(C*&); // #cwg126-nr
395 virtual void ncr() throw(C*const&);
397 virtual void ref1() throw(C *const&);
398 virtual void ref2() throw(C *);
400 virtual void v() throw(int);
401 virtual void w() throw(const int);
402 virtual void x() throw(int*); // #cwg126-x
403 virtual void y() throw(const int*);
404 virtual void z() throw(int); // #cwg126-z
406 struct B : A {
407 virtual void cp() throw(C*);
408 virtual void dp() throw(D*);
409 virtual void ep() throw(E*);
410 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
411 // cxx98-14-note@#cwg126-ep {{overridden virtual function is here}}
412 virtual void fp() throw(F*);
413 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
414 // cxx98-14-note@#cwg126-fp {{overridden virtual function is here}}
415 virtual void gp() throw(G*);
416 virtual void hp() throw(H*);
417 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
418 // cxx98-14-note@#cwg126-hp {{overridden virtual function is here}}
420 virtual void cr() throw(C&);
421 virtual void dr() throw(D&);
422 virtual void er() throw(E&);
423 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
424 // cxx98-14-note@#cwg126-er {{overridden virtual function is here}}
425 virtual void fr() throw(F&);
426 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
427 // cxx98-14-note@#cwg126-fr {{overridden virtual function is here}}
428 virtual void gr() throw(G&);
429 virtual void hr() throw(H&);
430 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
431 // cxx98-14-note@#cwg126-hr {{overridden virtual function is here}}
433 virtual void pv() throw(C*);
435 #if __cplusplus >= 201103L
436 using nullptr_t = decltype(nullptr);
437 virtual void np() throw(nullptr_t);
438 virtual void npm() throw(nullptr_t&);
439 virtual void nr() throw(nullptr_t);
440 // cxx11-14-error@-1 {{exception specification of overriding function is more lax than base version}}
441 // cxx11-14-note@#cwg126-nr {{overridden virtual function is here}}
442 virtual void ncr() throw(nullptr_t);
443 #endif // __cplusplus >= 201103L
445 virtual void ref1() throw(D *const &);
446 virtual void ref2() throw(D *);
448 virtual void v() throw(const int);
449 virtual void w() throw(int);
450 virtual void x() throw(const int*);
451 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
452 // cxx98-14-note@#cwg126-x {{overridden virtual function is here}}
453 virtual void y() throw(int*); // ok
454 virtual void z() throw(long);
455 // cxx98-14-error@-1 {{exception specification of overriding function is more lax than base version}}
456 // cxx98-14-note@#cwg126-z {{overridden virtual function is here}}
458 #endif // __cplusplus <= 201402L
459 void f() throw(int);
460 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
461 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
464 namespace cwg127 { // cwg127: 2.9
465 __extension__ typedef __decltype(sizeof(0)) size_t;
466 template<typename T> struct A {
467 A() { throw 0; }
468 void *operator new(size_t, const char * = 0);
469 void operator delete(void *, const char *) { T::error; } // #cwg127-delete-const-char
470 // expected-error@#cwg127-delete-const-char {{type 'void' cannot be used prior to '::' because it has no members}}
471 // expected-note@#cwg127-p {{in instantiation of member function 'cwg127::A<void>::operator delete' requested here}}
472 // expected-error@#cwg127-delete-const-char {{type 'int' cannot be used prior to '::' because it has no members}}
473 // expected-note@#cwg127-q {{in instantiation of member function 'cwg127::A<int>::operator delete' requested here}}
474 void operator delete(void *) { T::error; }
476 A<void> *p = new A<void>; // #cwg127-p
477 A<int> *q = new ("") A<int>; // #cwg127-q
480 namespace cwg128 { // cwg128: yes
481 enum E1 { e1 } x = e1;
482 enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1);
485 // cwg129: dup 616
486 // cwg130: na
488 namespace cwg131 { // cwg131: sup P1949
489 const char *a_with_\u0e8c = "\u0e8c";
490 const char *b_with_\u0e8d = "\u0e8d";
491 const char *c_with_\u0e8e = "\u0e8e";
494 namespace cwg132 { // cwg132: no
495 void f() {
496 extern struct {} x; // ok
497 extern struct S {} y; // FIXME: This is invalid.
499 static enum { E } e;
502 // cwg133: dup 87
503 // cwg134: na
505 namespace cwg135 { // cwg135: yes
506 struct A {
507 A f(A a) { return a; }
508 friend A g(A a) { return a; }
509 static A h(A a) { return a; }
513 namespace cwg136 { // cwg136: 3.4
514 void f(int, int, int = 0); // #cwg136-f
515 void g(int, int, int); // #cwg136-g
516 struct A {
517 friend void f(int, int = 0, int);
518 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
519 // expected-note@#cwg136-f {{previous declaration is here}}
520 friend void g(int, int, int = 0);
521 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
522 // expected-note@#cwg136-g {{previous declaration is here}}
523 friend void h(int, int, int = 0);
524 // expected-error@-1 {{friend declaration specifying a default argument must be a definition}}
525 friend void i(int, int, int = 0) {} // #cwg136-A-i
526 friend void j(int, int, int = 0) {}
527 operator int();
529 void i(int, int, int);
530 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
531 // expected-note@#cwg136-A-i {{previous declaration is here}}
532 void q() {
533 j(A(), A()); // ok, has default argument
535 extern "C" void k(int, int, int, int); // #cwg136-k
536 namespace NSA {
537 struct A {
538 friend void cwg136::k(int, int, int, int = 0);
539 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
540 // expected-note@#cwg136-k {{previous declaration is here}}
543 namespace NSB {
544 struct A {
545 friend void cwg136::k(int, int, int = 0, int); // #cwg136-friend-k
546 // expected-error@#cwg136-friend-k {{friend declaration specifying a default argument must be the only declaration}}
547 // expected-note@#cwg136-k {{previous declaration is here}}
548 // expected-error@#cwg136-friend-k {{missing default argument on parameter}}
551 struct B {
552 void f(int); // #cwg136-B-f
554 struct C {
555 friend void B::f(int = 0);
556 // expected-error@-1 {{friend declaration specifying a default argument must be the only declaration}}
557 // expected-note@#cwg136-B-f {{previous declaration is here}}
561 namespace cwg137 { // cwg137: yes
562 extern void *p;
563 extern const void *cp;
564 extern volatile void *vp;
565 extern const volatile void *cvp;
566 int *q = static_cast<int*>(p);
567 int *qc = static_cast<int*>(cp);
568 // expected-error@-1 {{static_cast from 'const void *' to 'int *' casts away qualifiers}}
569 int *qv = static_cast<int*>(vp);
570 // expected-error@-1 {{static_cast from 'volatile void *' to 'int *' casts away qualifiers}}
571 int *qcv = static_cast<int*>(cvp);
572 // expected-error@-1 {{static_cast from 'const volatile void *' to 'int *' casts away qualifiers}}
573 const int *cq = static_cast<const int*>(p);
574 const int *cqc = static_cast<const int*>(cp);
575 const int *cqv = static_cast<const int*>(vp);
576 // expected-error@-1 {{static_cast from 'volatile void *' to 'const int *' casts away qualifiers}}
577 const int *cqcv = static_cast<const int*>(cvp);
578 // expected-error@-1 {{static_cast from 'const volatile void *' to 'const int *' casts away qualifiers}}
579 const volatile int *cvq = static_cast<const volatile int*>(p);
580 const volatile int *cvqc = static_cast<const volatile int*>(cp);
581 const volatile int *cvqv = static_cast<const volatile int*>(vp);
582 const volatile int *cvqcv = static_cast<const volatile int*>(cvp);
585 namespace cwg138 { // cwg138: partial
586 namespace example1 {
587 void foo(); // #cwg138-ex1-foo
588 namespace A {
589 using example1::foo; // #cwg138-ex1-using
590 class X {
591 static const int i = 10;
592 // This friend declaration is using neither qualified-id nor template-id,
593 // so name 'foo' is not looked up, which means the using-declaration has no effect.
594 // Target scope of this declaration is A, so this is grating friendship to
595 // (hypothetical) A::foo instead of 'example1::foo' using declaration refers to.
596 // A::foo corresponds to example1::foo named by the using declaration,
597 // and since A::foo is a different entity, they potentially conflict.
598 // FIXME: This is ill-formed, but not for the reason diagnostic says.
599 friend void foo();
600 // expected-error@-1 {{cannot befriend target of using declaration}}
601 // expected-note@#cwg138-ex1-foo {{target of using declaration}}
602 // expected-note@#cwg138-ex1-using {{using declaration}}
605 } // namespace example1
607 namespace example2 {
608 void f();
609 void g();
610 class B {
611 void g();
613 class A : public B {
614 static const int i = 10;
615 void f();
616 // Both friend declaration are not using qualified-ids or template-ids,
617 // so 'f' and 'g' are not looked up, which means that presence of A::f
618 // and base B have no effect.
619 // Both target scope of namespace 'example2', and grant friendship to
620 // example2::f and example2::g respectively.
621 friend void f();
622 friend void g();
624 void f() {
625 int i2 = A::i;
627 void g() {
628 int i3 = A::i;
630 } // namespace example2
632 namespace example3 {
633 struct Base {
634 private:
635 static const int i = 10; // #cwg138-ex3-Base-i
637 public:
638 struct Data;
639 // Elaborated type specifier is not the sole constituent of declaration,
640 // so 'Data' undergoes unqualified type-only lookup, which finds Base::Data.
641 friend class Data;
643 struct Data {
644 void f() {
645 int i2 = Base::i;
649 struct Data {
650 void f() {
651 int i2 = Base::i;
652 // expected-error@-1 {{'i' is a private member of 'cwg138::example3::Base'}}
653 // expected-note@#cwg138-ex3-Base-i {{declared private here}}
656 } // namespace example3
657 } // namespace cwg138
659 namespace cwg139 { // cwg139: yes
660 namespace example1 {
661 typedef int f; // #cwg139-typedef-f
662 struct A {
663 friend void f(A &);
664 // expected-error@-1 {{redefinition of 'f' as different kind of symbol}}
665 // expected-note@#cwg139-typedef-f {{previous definition is here}}
669 namespace example2 {
670 typedef int f;
671 namespace N {
672 struct A {
673 friend void f(A &);
674 operator int();
675 void g(A a) { int i = f(a); } // ok, f is typedef not friend function
681 namespace cwg140 { // cwg140: yes
682 void f(int *const) {} // #cwg140-f-first
683 void f(int[3]) {}
684 // expected-error@-1 {{redefinition of 'f'}}
685 // expected-note@#cwg140-f-first {{previous definition is here}}
686 void g(const int);
687 void g(int n) { n = 2; }
690 namespace cwg141 { // cwg141: 3.1
691 template<typename T> void f();
692 template<typename T> struct S { int n; }; // #cwg141-S
693 struct A : S<int> {
694 template<typename T> void f();
695 template<typename T> struct S {}; // #cwg141-A-S
696 } a;
697 struct B : S<int> {} b;
698 void g() {
699 a.f<int>();
700 (void)a.S<int>::n; // #cwg141-a
701 // cxx98-error@#cwg141-a {{lookup of 'S' in member access expression is ambiguous; using member of 'struct A'}}
702 // cxx98-note@#cwg141-A-S {{lookup in the object type 'struct A' refers here}}
703 // cxx98-note@#cwg141-S {{lookup from the current scope refers here}}
704 // expected-error@#cwg141-a {{no member named 'n' in 'cwg141::A::S<int>'; did you mean '::cwg141::S<int>::n'?}}
705 // expected-note@#cwg141-S {{'::cwg141::S<int>::n' declared here}}
706 // FIXME: we issue a useful diagnostic first, then some bogus ones.
707 b.f<int>();
708 // expected-error@-1 {{no member named 'f' in 'cwg141::B'}}
709 // expected-error@-2 +{{}}
710 (void)b.S<int>::n;
712 template<typename T> struct C {
713 T t;
714 void g() {
715 t.f<int>();
716 // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent template name}}
718 void h() {
719 (void)t.S<int>::n; // ok
721 void i() {
722 (void)t.S<int>(); // ok!
725 void h() { C<B>().h(); } // ok
726 struct X {
727 template<typename T> void S();
729 void i() { C<X>().i(); } // ok!!
732 namespace cwg142 { // cwg142: 2.8
733 class B { // #cwg142-B
734 public:
735 int mi; // #cwg142-B-mi
736 static int si; // #cwg142-B-si
738 class D : private B { // #cwg142-D
740 class DD : public D {
741 void f();
743 void DD::f() {
744 mi = 3;
745 // expected-error@-1 {{'mi' is a private member of 'cwg142::B'}}
746 // expected-note@#cwg142-D {{constrained by private inheritance here}}
747 // expected-note@#cwg142-B-mi {{member is declared here}}
748 si = 3;
749 // expected-error@-1 {{'si' is a private member of 'cwg142::B'}}
750 // expected-note@#cwg142-D {{constrained by private inheritance here}}
751 // expected-note@#cwg142-B-si {{member is declared here}}
752 B b_old;
753 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}}
754 // expected-note@#cwg142-D {{constrained by private inheritance here}}
755 // expected-note@#cwg142-B {{member is declared here}}
756 cwg142::B b;
757 b.mi = 3;
758 b.si = 3;
759 B::si = 3;
760 // expected-error@-1 {{'B' is a private member of 'cwg142::B'}}
761 // expected-note@#cwg142-D {{constrained by private inheritance here}}
762 // expected-note@#cwg142-B {{member is declared here}}
763 cwg142::B::si = 3;
764 B *bp1_old = this; // #cwg142-bp1_old
765 // expected-error@#cwg142-bp1_old {{'B' is a private member of 'cwg142::B'}}
766 // expected-note@#cwg142-D {{constrained by private inheritance here}}
767 // expected-note@#cwg142-B {{member is declared here}}
768 // expected-error@#cwg142-bp1_old {{cannot cast 'cwg142::DD' to its private base class 'B'}}
769 // expected-note@#cwg142-D {{declared private here}}
770 cwg142::B *bp1 = this;
771 // expected-error@-1 {{cannot cast 'cwg142::DD' to its private base class 'cwg142::B'}}
772 // expected-note@#cwg142-D {{declared private here}}
773 B *bp2_old = (B*)this; // #cwg142-bp2_old
774 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}}
775 // expected-note@#cwg142-D {{constrained by private inheritance here}}
776 // expected-note@#cwg142-B {{member is declared here}}
777 // expected-error@#cwg142-bp2_old {{'B' is a private member of 'cwg142::B'}}
778 // expected-note@#cwg142-D {{constrained by private inheritance here}}
779 // expected-note@#cwg142-B {{member is declared here}}
780 cwg142::B *bp2 = (cwg142::B*)this;
781 bp2->mi = 3;
785 namespace cwg143 { // cwg143: yes
786 namespace A { struct X; }
787 namespace B { void f(A::X); }
788 namespace A {
789 struct X { friend void B::f(X); };
791 void g(A::X x) {
792 f(x);
793 // expected-error@-1 {{use of undeclared identifier 'f'}}
797 namespace cwg145 { // cwg145: yes
798 void f(bool b) {
799 ++b;
800 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}}
801 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
802 b++;
803 // cxx98-14-warning@-1 {{incrementing expression of type bool is deprecated and incompatible with C++17}}
804 // since-cxx17-error@-2 {{ISO C++17 does not allow incrementing expression of type bool}}
808 namespace cwg147 { // cwg147: yes
809 namespace example1 {
810 template<typename> struct A {
811 template<typename T> A(T);
813 // Per core issue 1435, this is ill-formed because A<int>::A<int> does not
814 // name the injected-class-name. (A<int>::A does, though.)
815 template<> template<> A<int>::A<int>(int) {}
816 // expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}}
817 template<> template<> A<float>::A(float) {}
819 namespace example2 {
820 struct A { A(); };
821 struct B : A { B(); };
822 A::A a1;
823 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a type in this context}}
824 B::A a2;
826 namespace example3 {
827 template<typename> struct A {
828 template<typename T> A(T);
829 static A a;
831 template<> A<int>::A<int>(A<int>::a);
832 // expected-error@-1 {{qualified reference to 'A' is a constructor name rather than a template name in this context}}
836 namespace cwg148 { // cwg148: yes
837 struct A { int A::*p; };
838 static_assert(__is_pod(int(A::*)), "");
839 static_assert(__is_pod(A), "");
842 // cwg149: na
844 namespace cwg150 { // cwg150: 19
845 namespace p1 {
846 template <class T, class U = int>
847 class ARG { };
849 template <class X, template <class Y> class PARM>
850 void f(PARM<X>) { }
852 void g() {
853 ARG<int> x;
854 f(x);
856 } // namespace p1
858 namespace p2 {
859 template <template <class T, class U = int> class PARM>
860 class C {
861 PARM<int> pi;
863 } // namespace p2
865 namespace n1 {
866 struct Dense { static const unsigned int dim = 1; };
868 template <template <typename> class View,
869 typename Block>
870 void operator+(float, View<Block> const&);
872 template <typename Block,
873 unsigned int Dim = Block::dim>
874 class Lvalue_proxy { operator float() const; };
876 void test_1d (void) {
877 Lvalue_proxy<Dense> p;
878 float b;
879 b + p;
881 } // namespace n1
884 namespace cwg151 { // cwg151: 3.1
885 struct X {};
886 typedef int X::*p;
887 static_assert(__enable_constant_folding(p() == 0), "");
890 namespace cwg152 { // cwg152: yes
891 struct A {
892 A(); // #cwg152-A-ctor
893 explicit A(const A&); // #cwg152-A-explicit-ctor
895 A a1 = A();
896 // cxx98-14-error@-1 {{no matching constructor for initialization of 'A'}}
897 // cxx98-14-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}}
898 // cxx98-14-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
899 A a2((A()));
901 A &f();
902 A a3 = f();
903 // expected-error@-1 {{no matching constructor for initialization of 'A'}}
904 // expected-note@#cwg152-A-explicit-ctor {{explicit constructor is not a candidate}}
905 // expected-note@#cwg152-A-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
906 A a4(f());
909 // cwg153: na
911 namespace cwg154 { // cwg154: yes
912 union { int a; };
913 // expected-error@-1 {{nonymous unions at namespace or global scope must be declared 'static'}}
914 namespace {
915 union { int b; };
917 static union { int c; };
920 namespace cwg155 { // cwg155: dup 632
921 struct S { int n; } s = { { 1 } };
922 // expected-warning@-1 {{braces around scalar initializer}}
925 // cwg158 is in cwg158.cpp
927 namespace cwg159 { // cwg159: 3.5
928 namespace X { void f(); }
929 void f();
930 void cwg159::f() {}
931 // expected-warning@-1 {{extra qualification on member 'f'}}
932 void cwg159::X::f() {}
935 // cwg160: na
937 namespace cwg161 { // cwg161: 3.1
938 class A {
939 protected:
940 struct B { int n; } b; // #cwg161-B
941 static B bs;
942 void f(); // #cwg161-f
943 static void sf();
945 struct C : A {};
946 struct D : A {
947 void g(C c) {
948 (void)b.n;
949 B b1;
950 C::B b2; // ok, accessible as a member of A
951 (void)&C::b;
952 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}
953 // expected-note@#cwg161-B {{declared protected here}}
954 (void)&C::bs;
955 (void)c.b;
956 // expected-error@-1 {{'b' is a protected member of 'cwg161::A'}}
957 // expected-note@#cwg161-B {{declared protected here}}
958 (void)c.bs;
959 f();
960 sf();
961 c.f();
962 // expected-error@-1 {{protected}}
963 // expected-note@#cwg161-f {{declared protected here}}
964 c.sf();
965 A::f();
966 D::f();
967 A::sf();
968 C::sf();
969 D::sf();
974 namespace cwg162 { // cwg162: 19
975 struct A {
976 char &f(char);
977 static int &f(int);
979 void g() {
980 int &a = (&A::f)(0);
981 char &b = (&A::f)('0');
982 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
986 int &c = (&A::f)(0);
987 char &d = (&A::f)('0');
988 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
991 // cwg163: na
993 namespace cwg164 { // cwg164: yes
994 void f(int);
995 template <class T> int g(T t) { return f(t); }
997 enum E { e };
998 int f(E);
1000 int k = g(e);
1003 namespace cwg165 { // cwg165: no
1004 namespace N {
1005 struct A { friend struct B; };
1006 void f() { void g(); }
1008 // FIXME: cwg1477 says this is ok, cwg165 says it's ill-formed
1009 struct N::B {};
1010 // FIXME: cwg165 says this is ill-formed, but the argument in cwg1477 says it's ok
1011 void N::g() {}
1014 namespace cwg166 { // cwg166: 2.9
1015 namespace A { class X; }
1017 template<typename T> int f(T t) { return t.n; }
1018 int g(A::X);
1019 template<typename T> int h(T t) { return t.n; }
1020 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}
1021 // expected-note@#cwg166-h-instantiation {{in instantiation of function template specialization 'cwg166::h<cwg166::A::X>' requested here}}
1022 // expected-note@#cwg166-X-n {{implicitly declared private here}}
1023 int i(A::X);
1025 namespace A {
1026 class X {
1027 friend int f<X>(X);
1028 friend int cwg166::g(X);
1029 friend int h(X);
1030 friend int i(X);
1031 int n; // #cwg166-X-n
1034 int h(X x) { return x.n; }
1035 int i(X x) { return x.n; }
1038 template int f(A::X);
1039 int g(A::X x) { return x.n; }
1040 template int h(A::X); // #cwg166-h-instantiation
1041 int i(A::X x) { return x.n; }
1042 // expected-error@-1 {{'n' is a private member of 'cwg166::A::X'}}
1043 // expected-note@#cwg166-X-n {{implicitly declared private here}}
1046 // cwg167: sup 1012
1048 namespace cwg168 { // cwg168: no
1049 extern "C" typedef int (*p)();
1050 extern "C++" typedef int (*q)();
1051 struct S {
1052 static int f();
1054 p a = &S::f; // FIXME: this should fail.
1055 q b = &S::f;
1058 namespace cwg169 { // cwg169: yes
1059 template<typename> struct A { int n; };
1060 struct B {
1061 template<typename> struct C;
1062 template<typename> void f();
1063 template<typename> static int n;
1064 // cxx98-11-error@-1 {{variable templates are a C++14 extension}}
1066 struct D : A<int>, B {
1067 using A<int>::n;
1068 using B::C<int>;
1069 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
1070 using B::f<int>;
1071 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
1072 using B::n<int>;
1073 // expected-error@-1 {{using declaration cannot refer to a template specialization}}
1077 namespace { // cwg171: 3.4
1078 int cwg171a;
1080 int cwg171b; // #cwg171b-int
1081 namespace cwg171 {
1082 extern "C" void cwg171a();
1083 extern "C" void cwg171b();
1084 // expected-error@-1 {{declaration of 'cwg171b' with C language linkage conflicts with declaration in global scope}}
1085 // expected-note@#cwg171b-int {{declared in global scope here}}
1088 namespace cwg172 { // cwg172: yes
1089 enum { zero };
1090 static_assert(-1 < zero, "");
1092 enum { x = -1, y = (unsigned int)-1 };
1093 static_assert(sizeof(x) > sizeof(int), "");
1095 enum { a = (unsigned int)-1 / 2 };
1096 static_assert(sizeof(a) == sizeof(int), "");
1097 static_assert(-a < 0, "");
1099 enum { b = (unsigned int)-1 / 2 + 1 };
1100 static_assert(sizeof(b) == sizeof(unsigned int), "");
1101 static_assert(-b > 0, "");
1103 enum { c = (unsigned long)-1 / 2 };
1104 static_assert(sizeof(c) == sizeof(long), "");
1105 static_assert(-c < 0, "");
1107 enum { d = (unsigned long)-1 / 2 + 1 };
1108 static_assert(sizeof(d) == sizeof(unsigned long), "");
1109 static_assert(-d > 0, "");
1111 enum { e = (unsigned long long)-1 / 2 };
1112 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1113 static_assert(sizeof(e) == sizeof(long), "");
1114 static_assert(-e < 0, "");
1116 enum { f = (unsigned long long)-1 / 2 + 1 };
1117 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1118 static_assert(sizeof(f) == sizeof(unsigned long), "");
1119 static_assert(-f > 0, "");
1122 namespace cwg173 { // cwg173: yes
1123 static_assert('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&
1124 '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&
1125 '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9', "");
1128 // cwg174: sup 1012
1130 namespace cwg175 { // cwg175: 2.8
1131 struct A {}; // #cwg175-A
1132 struct B : private A {}; // #cwg175-B
1133 struct C : B {
1134 A a;
1135 // expected-error@-1 {{'A' is a private member of 'cwg175::A'}}
1136 // expected-note@#cwg175-B {{constrained by private inheritance here}}
1137 // expected-note@#cwg175-A {{member is declared here}}
1138 cwg175::A b;
1142 namespace cwg176 { // cwg176: 3.1
1143 template<typename T> class Y;
1144 template<> class Y<int> {
1145 void f() {
1146 typedef Y A; // #cwg176-A-first
1147 typedef Y<char> A;
1148 // expected-error@-1 {{typedef redefinition with different types ('Y<char>' vs 'Y<int>')}}
1149 // expected-note@#cwg176-A-first {{previous definition is here}}
1153 template<typename T> struct Base {}; // #cwg176-Base
1154 template<typename T> struct Derived : public Base<T> {
1155 void f() {
1156 typedef typename Derived::template Base<T> A;
1157 typedef typename Derived::Base A;
1160 template struct Derived<int>;
1162 template<typename T> struct Derived2 : Base<int>, Base<char> {
1163 typename Derived2::Base b;
1164 // expected-error@-1 {{member 'Base' found in multiple base classes of different types}}
1165 // expected-note@#cwg176-Base {{member type 'cwg176::Base<int>' found by ambiguous name lookup}}
1166 // expected-note@#cwg176-Base {{member type 'cwg176::Base<char>' found by ambiguous name lookup}}
1167 typename Derived2::Base<double> d;
1170 template<typename T> class X { // #cwg176-X
1171 X *p1;
1172 X<T> *p2;
1173 X<int> *p3;
1174 cwg176::X *p4; // #cwg176-p4
1175 // cxx98-14-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments}}
1176 // cxx98-14-note@#cwg176-X {{template is declared here}}
1177 // since-cxx17-error@#cwg176-p4 {{use of class template 'cwg176::X' requires template arguments; argument deduction not allowed in non-static class member}}
1178 // since-cxx17-note@#cwg176-X {{template is declared here}}
1182 namespace cwg177 { // cwg177: yes
1183 struct B {};
1184 struct A {
1185 A(A &); // #cwg177-A-copy-ctor
1186 A(const B &); // #cwg177-A-ctor-from-B
1188 B b;
1189 A a = b;
1190 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'A'}}
1191 // cxx98-14-note@#cwg177-A-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1192 // cxx98-14-note@#cwg177-A-ctor-from-B {{candidate constructor not viable: no known conversion from 'A' to 'const B &' for 1st argument}}
1194 struct C { C(C&); }; // #cwg177-C-copy-ctor
1195 struct D : C {};
1196 struct E { operator D(); };
1197 E e;
1198 C c = e;
1199 // expected-error@-1 {{no viable constructor copying variable of type 'D'}}
1200 // expected-note@#cwg177-C-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1203 namespace cwg178 { // cwg178: yes
1204 static_assert(int() == 0, "");
1205 #if __cplusplus >= 201103L
1206 static_assert(int{} == 0, "");
1207 struct S { int a, b; };
1208 static_assert(S{1}.b == 0, "");
1209 struct T { constexpr T() : n() {} int n; };
1210 static_assert(T().n == 0, "");
1211 struct U : S { constexpr U() : S() {} };
1212 static_assert(U().b == 0, "");
1213 #endif
1216 namespace cwg179 { // cwg179: yes
1217 void f();
1218 int n = &f - &f;
1219 // expected-error@-1 {{arithmetic on pointers to the function type 'void ()'}}
1222 namespace cwg180 { // cwg180: 2.8
1223 template<typename T> struct X : T, T::some_base {
1224 X() : T::some_type_that_might_be_T(), T::some_base() {}
1225 friend class T::some_class;
1226 void f() {
1227 enum T::some_enum e;
1232 namespace cwg181 { // cwg181: yes
1233 namespace X {
1234 template <template X<class T> > struct A { };
1235 // expected-error@-1 +{{}}
1236 template <template X<class T> > void f(A<X>) { }
1237 // expected-error@-1 +{{}}
1240 namespace Y {
1241 template <template <class T> class X> struct A { };
1242 template <template <class T> class X> void f(A<X>) { }
1246 namespace cwg182 { // cwg182: 14
1247 template <class T> struct C {
1248 void f();
1249 void g();
1252 template <class T> void C<T>::f() {}
1253 template <class T> void C<T>::g() {}
1255 class A {
1256 class B {};
1257 void f();
1260 template void C<A::B>::f();
1261 template <> void C<A::B>::g();
1263 void A::f() {
1264 C<B> cb;
1265 cb.f();
1269 namespace cwg183 { // cwg183: sup 382
1270 template<typename T> struct A {};
1271 template<typename T> struct B {
1272 typedef int X;
1274 template<> struct A<int> {
1275 typename B<int>::X x;
1276 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1280 namespace cwg184 { // cwg184: yes
1281 template<typename T = float> struct B {};
1283 template<template<typename TT = float> class T> struct A {
1284 void f();
1285 void g();
1288 template<template<typename TT> class T> void A<T>::f() { // #cwg184-T
1289 T<> t;
1290 // expected-error@-1 {{too few template arguments for template template parameter 'T'}}
1291 // expected-note@#cwg184-T {{template is declared here}}
1294 template<template<typename TT = char> class T> void A<T>::g() {
1295 T<> t;
1296 typedef T<> X;
1297 typedef T<char> X;
1300 void h() { A<B>().g(); }
1303 // cwg185 is in cwg185.cpp
1305 namespace cwg187 { // cwg187: sup 481
1306 const int Z = 1;
1307 template<int X = Z, int Z = X> struct A;
1308 typedef A<> T;
1309 typedef A<1, 1> T;
1312 namespace cwg188 { // cwg188: yes
1313 char c[10];
1314 static_assert(sizeof(0, c) == 10, "");
1317 // cwg190 FIXME: add codegen test for tbaa
1318 // or implement C++20 std::is_layout_compatible and test it this way
1320 int cwg191_j;
1321 namespace cwg191 { // cwg191: yes
1322 namespace example1 {
1323 struct outer {
1324 static int i;
1325 struct inner {
1326 void f() {
1327 struct local {
1328 void g() {
1329 i = 5;
1337 namespace example2 {
1338 struct S {
1339 void f() {
1340 struct local2 {
1341 void g() {
1342 cwg191_j = 5;
1350 // cwg193 is in cwg193.cpp
1352 namespace cwg194 { // cwg194: yes
1353 struct A {
1354 A();
1355 void A();
1356 // expected-error@-1 {{constructor cannot have a return type}}
1358 struct B {
1359 void B();
1360 // expected-error@-1 {{constructor cannot have a return type}}
1361 B();
1363 struct C {
1364 inline explicit C(int) {}
1368 namespace cwg195 { // cwg195: yes
1369 void f();
1370 int *p = (int*)&f;
1371 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}
1372 void (*q)() = (void(*)())&p;
1373 // cxx98-error@-1 {{cast between pointer-to-function and pointer-to-object is an extension}}
1376 namespace cwg197 { // cwg197: yes
1377 char &f(char);
1379 template <class T> void g(T t) {
1380 char &a = f(1);
1381 char &b = f(T(1));
1382 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
1383 // expected-note@#cwg197-g-e-call {{in instantiation of function template specialization 'cwg197::g<cwg197::E>' requested here}}
1384 char &c = f(t);
1385 // expected-error@-1 {{non-const lvalue reference to type 'char' cannot bind to a value of unrelated type 'int'}}
1388 void f(int);
1390 enum E { e };
1391 int &f(E);
1393 void h() {
1394 g('a');
1395 g(2);
1396 g(e); // #cwg197-g-e-call
1400 namespace cwg198 { // cwg198: yes
1401 struct A {
1402 int n;
1403 struct B {
1404 int m[sizeof(n)];
1405 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1406 int f() { return n; }
1407 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}
1409 struct C;
1410 struct D;
1412 struct A::C {
1413 int m[sizeof(n)];
1414 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1415 int f() { return n; }
1416 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}
1418 struct A::D : A {
1419 int m[sizeof(n)];
1420 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
1421 int f() { return n; }
1425 // cwg199 is in cwg199.cpp