Debian Codegraph @

clang/test/CXX/drs/cwg6xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-17,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-20,cxx98-17,cxx11-17,cxx98-14,since-cxx11,cxx11 -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx11-20,cxx98-17,cxx11-17,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx11-20,cxx98-17,cxx11-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,cxx11-20,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
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 namespace cwg600 { // cwg600: 2.8
14 struct S {
15 void f(int);
16
17 private:
18 void f(double); // #cwg600-f-double
19 };
20
21 void g(S *sp) {
22 sp->f(2);
23 // access control is applied after overload resolution
24 sp->f(2.2);
25 // expected-error@-1 {{'f' is a private member of 'cwg600::S'}}
26 // expected-note@#cwg600-f-double {{declared private here}}
27 }
28 } // namespace cwg600
29
30 namespace std {
31 struct type_info {};
32 __extension__ typedef __SIZE_TYPE__ size_t;
33 } // namespace std
34
35 namespace cwg601 { // cwg601: yes
36 #if __cplusplus >= 201103L
37 #define MAX __LLONG_MAX__
38 #else
39 #define MAX __LONG_MAX__
40 #endif
41
42 #if 0x8000 < -1
43 #error 0x8000 should be signed
44 #endif
45
46 #if MAX > 0xFFFFFFFF && 0x80000000 < -1
47 #error 0x80000000 should be signed
48 #endif
49
50 #if __INT_MAX__ == 0x7FFFFFFF
51 static_assert(0x80000000 < -1, "0x80000000 should be unsigned");
52 #endif
53
54 #if MAX > 0xFFFFFFFFFFFFFFFF && 0x8000000000000000 < -1
55 #error 0x8000000000000000 should be signed
56 #endif
57
58 #if __cplusplus >= 201103L && __LLONG_MAX__ == 0x7FFFFFFFFFFFFFFF
59 static_assert(0x8000000000000000 < -1, "0x8000000000000000 should be unsigned");
60 #endif
61
62 #undef MAX
63 }
64
65 namespace cwg602 { // cwg602: yes
66 template<class T> struct A {
67 template<class U> friend struct A;
68 };
69
70 template<class T> struct B {
71 class C {
72 template<class U> friend struct B;
73 typedef int type;
74 };
75 typename C::type ct; // ok, befriended
76 };
77 B<int> b;
78 }
79
80 namespace cwg603 { // cwg603: yes
81 template<unsigned char> struct S {};
82 typedef S<'\001'> S1;
83 typedef S<(1ul << __CHAR_BIT__) + 1> S1;
84 // since-cxx11-error@-1 {{cannot be narrowed}}
85 }
86
87 // cwg604: na
88 // cwg605 is in cwg605.cpp
89
90 namespace cwg606 { // cwg606: 3.0
91 #if __cplusplus >= 201103L
92 template<typename T> struct S {};
93 template<typename T> void f(S<T> &&); // #cwg606-f
94 template<typename T> void g(T &&);
95 template<typename T> void h(const T &&); // #cwg606-h
96
97 void test(S<int> s) {
98 f(s);
99 // since-cxx11-error@-1 {{no matching function for call to 'f'}}
100 // since-cxx11-note@#cwg606-f {{candidate function [with T = int] not viable: expects an rvalue for 1st argument}}
101 g(s);
102 h(s);
103 // since-cxx11-error@-1 {{no matching function for call to 'h'}}
104 // since-cxx11-note@#cwg606-h {{candidate function [with T = cwg606::S<int>] not viable: expects an rvalue for 1st argument}}
105
106 g(test);
107 h(test); // ok, an rvalue reference can bind to a function lvalue
108 }
109 #endif
110 }
111
112 namespace cwg607 { // cwg607: yes
113 namespace example1 {
114 struct Y {};
115
116 template <typename T> struct X : public virtual Y {};
117
118 template <typename T> class A : public X<T> {
119 template <typename S> A(S) : S() {}
120 };
121
122 template A<int>::A(Y);
123 } // namespace example1
124
125 namespace example2 {
126 namespace N {
127 struct B {
128 B(int);
129 };
130 typedef B typedef_B;
131 struct D : B {
132 D();
133 };
134 } // namespace N
135
136 N::D::D() : typedef_B(0) {}
137 } // namespace example2
138 } // namespace cwg607
139
140 namespace cwg608 { // cwg608: yes
141 struct A { virtual void f(); };
142 struct B : A {};
143 struct C : A { void f(); };
144 struct D : B, C {};
145 }
146
147 static_assert(-0u == 0u, ""); // cwg610: yes
148
149 namespace cwg611 { // cwg611: yes
150 int k;
151 struct S { int &r; } s = { k ? k : k };
152 }
153
154 // cwg612: na
155
156 namespace cwg613 { // cwg613: yes c++11
157 // see also n2253
158 struct A { int n; static void f(); };
159 int f(int);
160 struct B { virtual void f(); };
161 B &g(int);
162
163 int an1 = sizeof(A::n);
164 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
165 int an2 = sizeof(A::n + 1); // valid per cwg850
166 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
167 int an3 = sizeof A::n;
168 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
169 int an4 = sizeof(f(A::n));
170 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
171 int an5 = sizeof(g(A::n));
172 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
173 const std::type_info &an6 = typeid(A::n);
174 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
175 const std::type_info &an7 = typeid(A::n + 1);
176 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
177 const std::type_info &an8 = typeid(f(A::n));
178 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}
179 const std::type_info &an9 = typeid(g(A::n));
180 // expected-error@-1 {{invalid use of non-static data member 'n'}}
181
182 void A::f() {
183 int an1 = sizeof n;
184 // cxx98-error@-1 {{invalid use of member 'n' in static member function}}
185 const std::type_info &an2 = typeid(n + 1);
186 // cxx98-error@-1 {{invalid use of member 'n' in static member function}}
187 const std::type_info &an3 = typeid(g(n));
188 // cxx98-error@-1 {{invalid use of member 'n' in static member function}}
189 // since-cxx11-error@-2 {{invalid use of non-static data member 'n'}}
190 }
191 }
192
193 static_assert((-1) / 2 == 0, ""); // cwg614: yes
194 static_assert((-1) % 2 == -1, "");
195
196 namespace cwg615 { // cwg615: yes
197 int f();
198 static int n = f();
199 }
200
201 namespace cwg616 { // cwg616: 4
202 #if __cplusplus >= 201103L
203 struct S { int n; } s;
204 S f();
205 using T = decltype((S().n));
206 using T = decltype((static_cast<S&&>(s).n));
207 using T = decltype((f().n));
208 using T = decltype(S().*&S::n);
209 using T = decltype(static_cast<S&&>(s).*&S::n);
210 using T = decltype(f().*&S::n);
211 using T = int&&;
212
213 using U = decltype(S().n);
214 using U = decltype(static_cast<S&&>(s).n);
215 using U = int;
216 #endif
217 }
218
219 namespace cwg618 { // cwg618: yes
220 #if (unsigned)-1 > 0
221 #error wrong
222 #endif
223 }
224
225 namespace cwg619 { // cwg619: yes
226 extern int x[10];
227 struct S { static int x[10]; };
228
229 int x[];
230 static_assert(sizeof(x) == sizeof(int) * 10, "");
231 extern int x[];
232 static_assert(sizeof(x) == sizeof(int) * 10, "");
233
234 int S::x[];
235 static_assert(sizeof(S::x) == sizeof(int) * 10, "");
236
237 void f() {
238 extern int x[];
239 sizeof(x);
240 // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
241 }
242 }
243
244 // cwg620: dup 568
245
246 namespace cwg621 { // cwg621: yes
247 template<typename T> T f();
248 template<> int f() {} // #cwg621-f
249 template<> int f<int>() {}
250 // expected-error@-1 {{redefinition of 'f<int>'}}
251 // expected-note@#cwg621-f {{previous definition is here}}
252 }
253
254 // cwg623: na
255 // FIXME: Add documentation saying we allow invalid pointer values.
256
257 // cwg624 needs a libc++abi test.
258
259 namespace cwg625 { // cwg625: yes
260 template<typename T> struct A {};
261 A<auto> x = A<int>();
262 // cxx98-error@-1 {{'auto' type specifier is a C++11 extension}}
263 // expected-error@-2 {{'auto' not allowed in template argument}}
264 void f(int);
265 void (*p)(auto) = f;
266 // cxx98-error@-1 {{'auto' type specifier is a C++11 extension}}
267 // expected-error@-2 {{'auto' not allowed in function prototype}}
268 }
269
270 namespace cwg626 { // cwg626: yes
271 #define STR(x) #x
272 char c[2] = STR(c); // ok, type matches
273 wchar_t w[2] = STR(w);
274 // expected-error@-1 {{initializing wide char array with non-wide string literal}}
275 }
276
277 namespace cwg627 { // cwg627: yes
278 void f() {
279 // FIXME: emitted diagnostic have a room for improvement
280 true a = 0;
281 // expected-error@-1 {{expected ';' after expression}}
282 // expected-error@-2 {{use of undeclared identifier 'a'}}
283 // expected-warning@-3 {{expression result unused}}
284 }
285 }
286
287 // cwg628: na
288
289 namespace cwg629 { // cwg629: 2.9
290 typedef int T;
291 int n = 1;
292 void f() {
293 auto T = 2; // #cwg629-T
294 // cxx98-error@-1 {{expected unqualified-id}}
295
296 auto T(n);
297 // since-cxx11-error@-1 {{redefinition of 'T'}}
298 // since-cxx11-note@#cwg629-T {{previous definition is here}}
299 }
300 }
301
302 namespace cwg630 { // cwg630: yes
303 const bool MB_EQ_WC =
304 ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' &&
305 '\n' == L'\n' && //
306 'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' &&
307 'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' &&
308 'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' &&
309 'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' &&
310 'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' &&
311 'z' == L'z' && //
312 'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' &&
313 'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' &&
314 'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' &&
315 'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' &&
316 'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' &&
317 'Z' == L'Z' && //
318 '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' &&
319 '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' &&
320 '9' == L'9' && //
321 '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' &&
322 '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' &&
323 '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' &&
324 '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' &&
325 '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' &&
326 ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\'';
327 #if __STDC_MB_MIGHT_NEQ_WC__
328 #ifndef __FreeBSD__ // PR22208, FreeBSD expects us to give a bad (but conforming) answer here.
329 static_assert(!MB_EQ_WC, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation");
330 #endif
331 #else
332 static_assert(MB_EQ_WC, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs");
333 #endif
334 }
335
336 // cwg631: na
337
338 namespace cwg632 { // cwg632: yes
339 struct S { int n; } s = {{5}};
340 // expected-warning@-1 {{braces around scalar initializer}}
341 }
342
343 // cwg633: na
344 // see also n2993
345
346 namespace cwg634 { // cwg634: yes
347 struct S { S(); S(const S&); virtual void f(); ~S(); };
348 int f(...);
349 char f(int);
350 template<typename T> int (&g(T))[sizeof f(T())];
351 int (&a)[sizeof(int)] = g(S());
352 int (&b)[1] = g(0);
353 int k = f(S());
354 // cxx98-error@-1 {{cannot pass object of non-POD type 'S' through variadic function; call will abort at runtime}}
355 // since-cxx11-error@-2 {{cannot pass object of non-trivial type 'S' through variadic function; call will abort at runtime}}
356 }
357
358 namespace cwg635 { // cwg635: yes
359 template<typename T> struct A { A(); ~A(); };
360 template<typename T> A<T>::A<T>() {}
361 // expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}}
362 template<typename T> A<T>::~A<T>() {}
363
364 template<typename T> struct B { B(); ~B(); };
365 template<typename T> B<T>::B() {}
366 template<typename T> B<T>::~B() {}
367
368 struct C { template<typename T> C(); C(); };
369 template<typename T> C::C() {}
370 C::C() {}
371 template<> C::C<int>() {}
372 // expected-error@-1 {{qualified reference to 'C' is a constructor name rather than a type in this context}}
373 // expected-error@-2 {{expected unqualified-id}}
374 /*FIXME: needed for error recovery:*/;
375
376 template<typename T> struct D { template<typename U> D(); D(); };
377 template<typename T> D<T>::D() {} // #cwg635-D
378 template<typename T> template<typename U> D<T>::D() {}
379 template<typename T> D<T>::D<T>() {} // #cwg635-D-T
380 // expected-error@#cwg635-D-T {{out-of-line constructor for 'D' cannot have template arguments}}
381 // expected-error@#cwg635-D-T {{redefinition of 'D<T>'}}
382 // expected-note@#cwg635-D {{previous definition is here}}
383 }
384
385 namespace cwg637 { // cwg637: yes
386 void f(int i) {
387 i = ++i + 1;
388 i = i++ + 1;
389 // cxx98-14-warning@-1 {{multiple unsequenced modifications to 'i'}}
390 }
391 }
392
393 namespace cwg638 { // cwg638: no
394 template<typename T> struct A {
395 struct B;
396 void f();
397 void g();
398 struct C {
399 void h();
400 };
401 };
402
403 class X {
404 typedef int type;
405 template<class T> friend struct A<T>::B;
406 // expected-warning@-1 {{dependent nested name specifier 'A<T>::' for friend class declaration is not supported; turning off access control for 'X'}}
407 template<class T> friend void A<T>::f();
408 // expected-warning@-1 {{dependent nested name specifier 'A<T>::' for friend class declaration is not supported; turning off access control for 'X'}}
409 template<class T> friend void A<T>::g();
410 // expected-warning@-1 {{dependent nested name specifier 'A<T>::' for friend class declaration is not supported; turning off access control for 'X'}}
411 template<class T> friend void A<T>::C::h();
412 // expected-warning@-1 {{dependent nested name specifier 'A<T>::C::' for friend class declaration is not supported; turning off access control for 'X'}}
413 };
414
415 template<> struct A<int> {
416 X::type a; // FIXME: private
417 struct B {
418 X::type b; // ok
419 };
420 int f() { X::type c; } // FIXME: private
421 void g() { X::type d; } // ok
422 struct D {
423 void h() { X::type e; } // FIXME: private
424 };
425 };
426 }
427
428 namespace cwg639 { // cwg639: 3.3
429 void f(int i) {
430 void((i = 0) + (i = 0));
431 // expected-warning@-1 {{multiple unsequenced modifications to 'i'}}
432 }
433 }
434
435 namespace cwg641 { // cwg641: yes
436 namespace std_example {
437 struct abc;
438
439 struct xyz {
440 xyz(); // #cwg641-xyz-ctor
441 xyz(xyz &); // #cwg641-xyz-copy-ctor
442
443 operator xyz &() = delete;
444 // expected-warning@-1 {{conversion function converting 'cwg641::std_example::xyz' to itself will never be used}}
445 // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}
446 operator abc &() = delete;
447 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
448 };
449
450 struct abc : xyz {};
451
452 template<typename T>
453 void use(T &); // #cwg641-use
454 void test() {
455 use<xyz>(xyz());
456 // expected-error@-1 {{no matching function for call to 'use'}}
457 // expected-note@#cwg641-use {{candidate function template not viable: expects an lvalue for 1st argument}}
458 use<const xyz>(xyz());
459 // cxx98-error@-1 {{no viable constructor copying parameter of type 'xyz'; C++98 requires a copy constructor when binding a reference to a temporary}}
460 // cxx98-note@#cwg641-xyz-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
461 // cxx98-note@#cwg641-xyz-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
462 }
463 }
464
465 template<typename T> struct error { typedef typename T::error type; };
466
467 struct A {
468 template<typename T, typename error<T>::type = 0> operator T() const;
469 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
470 };
471 A a;
472 void f(A&); // #cwg641-f
473 void g(const A ca) {
474 f(A());
475 // expected-error@-1 {{no matching function for call to 'f'}}
476 // expected-note@#cwg641-f {{candidate function not viable: expects an lvalue for 1st argument}}
477 f(ca);
478 // expected-error@-1 {{no matching function for call to 'f'}}
479 // expected-note@#cwg641-f {{candidate function not viable: 1st argument ('const A') would lose const qualifier}}
480 (void)A();
481 (void)ca;
482 }
483 }
484
485 namespace cwg642 { // cwg642: yes
486 void f() {
487 const int i = 2;
488 {
489 char i[i];
490 static_assert(sizeof(i) == 2, "");
491 }
492 }
493
494 struct s { int a; };
495 void g(int s) {
496 struct s *p = new struct s;
497 p->a = s;
498 }
499 }
500
501 #if __cplusplus >= 201103L
502 namespace cwg643 { // cwg643: 3.2
503 struct A {
504 int x;
505 auto f() -> decltype(this->x);
506 auto f(A &a) -> decltype(a.x);
507 auto g() -> decltype(x);
508 auto h() -> decltype(this->y);
509 // since-cxx11-error@-1 {{no member named 'y' in 'cwg643::A'}}
510 auto h(A &a) -> decltype(a.y);
511 // since-cxx11-error@-1 {{no member named 'y' in 'cwg643::A'}}
512 auto i() -> decltype(y);
513 // since-cxx11-error@-1 {{use of undeclared identifier 'y'}}
514 int y;
515 };
516 }
517 #endif
518
519 #if __cplusplus >= 201103L
520 namespace cwg644 { // cwg644: partial
521 struct A {
522 A() = default;
523 int x, y;
524 };
525 static_assert(__is_literal_type(A), "");
526
527 struct B : A {};
528 static_assert(__is_literal_type(B), "");
529
530 struct C : virtual A {};
531 static_assert(!__is_literal_type(C), "");
532
533 struct D { C c; };
534 static_assert(!__is_literal_type(D), "");
535
536 // FIXME: According to CWG644, E<C> is a literal type despite having virtual
537 // base classes. This appears to be a wording defect.
538 template<typename T>
539 struct E : T {
540 constexpr E() = default;
541 };
542 static_assert(!__is_literal_type(E<C>), "");
543 }
544 #endif
545
546 // cwg645 increases permission to optimize; it's not clear that it's possible to
547 // test for this.
548 // cwg645: na
549
550 #if __cplusplus >= 201103L
551 namespace cwg646 { // cwg646: sup 981
552 struct A {
553 constexpr A(const A&) = default; // ok
554 };
555
556 struct B {
557 constexpr B() {}
558 B(B&);
559 };
560 constexpr B b = {}; // ok
561 }
562 #endif
563
564 #if __cplusplus >= 201103L
565 namespace cwg647 { // cwg647: 3.1
566 // This is partially superseded by cwg1358.
567 struct A {
568 constexpr virtual void f() const;
569 constexpr virtual void g() const {}
570 // cxx11-17-error@-1 {{virtual function cannot be constexpr}}
571 };
572
573 struct X { virtual void f() const; }; // #cwg647-f
574 struct B : X {
575 constexpr void f() const {}
576 // cxx11-17-error@-1 {{virtual function cannot be constexpr}}
577 // cxx11-17-note@#cwg647-f {{overridden virtual function is here}}
578 };
579
580 struct NonLiteral { NonLiteral() {} }; // #cwg647-NonLiteral
581
582 struct C {
583 constexpr C(NonLiteral);
584 constexpr C(NonLiteral, int) {}
585 // cxx11-20-error@-1 {{constexpr constructor's 1st parameter type 'NonLiteral' is not a literal type}}
586 // cxx11-20-note@#cwg647-NonLiteral {{'NonLiteral' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors}}
587 constexpr C() try {} catch (...) {}
588 // cxx11-17-error@-1 {{function try block in constexpr constructor is a C++20 extension}}
589 // cxx11-error@-2 {{use of this statement in a constexpr constructor is a C++14 extension}}
590 };
591
592 struct D {
593 operator int() const;
594 constexpr D(int) {}
595 D(float); // #cwg647-D-float-ctor
596 };
597 constexpr int get();
598 struct E {
599 int n;
600 D d;
601
602 // FIXME: We should diagnose this, as the conversion function is not
603 // constexpr. However, that part of this issue is supreseded by cwg1364 and
604 // others; no diagnostic is required for this any more.
605 constexpr E()
606 : n(D(0)),
607 d(0) {}
608
609 constexpr E(int)
610 // cxx11-20-error@-1 {{constexpr constructor never produces a constant expression}}
611 // cxx11-20-note@#cwg647-int-d {{non-constexpr constructor 'D' cannot be used in a constant expression}}
612 // cxx11-20-note@#cwg647-D-float-ctor {{declared here}}
613 : n(0),
614 d(0.0f) {} // #cwg647-int-d
615 constexpr E(float f)
616 // cxx11-20-error@-1 {{never produces a constant expression}}
617 // cxx11-20-note@#cwg647-float-d {{non-constexpr constructor}}
618 // cxx11-20-note@#cwg647-D-float-ctor {{declared here}}
619 : n(get()),
620 d(D(0) + f) {} // #cwg647-float-d
621 };
622 }
623 #endif
624
625 #if __cplusplus >= 201103L
626 namespace cwg648 { // cwg648: yes
627 int f();
628 constexpr int a = (true ? 1 : f());
629 constexpr int b = false && f();
630 constexpr int c = true || f();
631 }
632 #endif
633
634 #if __cplusplus >= 201103L
635 namespace cwg649 { // cwg649: 3.5
636 // Maximum alignment is 8192 bytes for Windows, and 4 GB for Linux
637 alignas(0x200000000) int n;
638 // since-cxx11-error-re@-1 {{{{requested alignment must be (8192|4294967296) bytes or smaller}}}}
639 struct alignas(0x200000000) X {};
640 // since-cxx11-error-re@-1 {{{{requested alignment must be (8192|4294967296) bytes or smaller}}}}
641 struct Y {
642 int n alignas(0x200000000);
643 // since-cxx11-error-re@-1 {{{{requested alignment must be (8192|4294967296) bytes or smaller}}}}
644 };
645 struct alignas(256) Z {};
646 // This part is superseded by cwg2130 and eventually by aligned allocation support.
647 auto *p = new Z;
648 }
649 #endif
650
651 // cwg650 is in cwg650.cpp
652
653 #if __cplusplus >= 201103L
654 namespace cwg651 { // cwg651: yes
655 struct X {
656 virtual X &f();
657 };
658 struct Y : X {
659 Y &f();
660 };
661 using T = decltype(((X&&)Y()).f());
662 using T = X &;
663 }
664 #endif
665
666 #if __cplusplus >= 201103L
667 namespace cwg652 { // cwg652: yes
668 constexpr int n = 1.2 * 3.4;
669 static_assert(n == 4, "");
670 }
671 #endif
672
673 // cwg653 is in cwg653.cpp
674
675 #if __cplusplus >= 201103L
676 namespace cwg654 { // cwg654: sup 1423
677 void f() {
678 if (nullptr) {}
679 // since-cxx11-warning@-1 {{implicit conversion of nullptr constant to 'bool'}}
680 bool b = nullptr;
681 // since-cxx11-error@-1 {{cannot initialize a variable of type 'bool' with an rvalue of type 'std::nullptr_t'}}
682 if (nullptr == 0) {}
683 if (nullptr != 0) {}
684 if (nullptr <= 0) {}
685 // since-cxx11-error@-1 {{invalid operands to binary expression ('std::nullptr_t' and 'int')}}
686 if (nullptr == 1) {}
687 // since-cxx11-error@-1 {{invalid operands to binary expression ('std::nullptr_t' and 'int')}}
688 if (!nullptr) {}
689 // since-cxx11-warning@-1 {{implicit conversion of nullptr constant to 'bool'}}
690 decltype(nullptr) n = 0;
691 static_cast<int>(nullptr);
692 // since-cxx11-error@-1 {{static_cast from 'std::nullptr_t' to 'int' is not allowed}}
693 (void)static_cast<decltype(nullptr)>(0);
694 static_cast<decltype(nullptr)>(1);
695 // since-cxx11-error@-1 {{static_cast from 'int' to 'decltype(nullptr)' (aka 'std::nullptr_t') is not allowed}}
696 void(true ? nullptr : 0);
697 void(true ? 0 : nullptr);
698 }
699 }
700 #endif
701
702 namespace cwg655 { // cwg655: yes
703 struct A { A(int); }; // #cwg655-A
704 struct B : A {
705 A a; // #cwg655-a
706 B();
707 B(int) : B() {}
708 // cxx98-error@-1 {{delegating constructors are permitted only in C++11}}
709 B(int*) : A() {} // #cwg655-delegating-to-A
710 // expected-error@-1 {{no matching constructor for initialization of 'A'}}
711 // expected-note@#cwg655-A {{candidate constructor not viable: requires 1 argument, but 0 were provided}}
712 // expected-note@#cwg655-A {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided}}
713 // since-cxx11-note@#cwg655-A {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided}}
714 // expected-error@#cwg655-delegating-to-A {{constructor for 'cwg655::B' must explicitly initialize the member 'a' which does not have a default constructor}}
715 // expected-note@#cwg655-a {{member is declared here}}
716 // expected-note@#cwg655-A {{'cwg655::A' declared here}}
717 };
718 }
719
720 namespace cwg656 { // cwg656: yes
721 struct A { A(const A&) = delete; };
722 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
723 struct B : A {};
724 struct X { operator B(); } x;
725 const A &r = x;
726 struct Y : private A { // #cwg656-Y
727 operator B() volatile;
728 };
729 extern Y y;
730 extern volatile Y vy;
731 // Conversion not considered due to reference-related types.
732 const A &s = y;
733 // expected-error@-1 {{cannot cast 'const Y' to its private base class 'const A'}}
734 // expected-note@#cwg656-Y {{declared private here}}
735 const A &t = vy;
736 // expected-error@-1 {{binding reference of type 'const A' to value of type 'volatile Y' drops 'volatile' qualifier}}
737
738 struct C { operator struct D(); } c;
739 struct D : C {};
740 const D &d = c; // ok, D not reference-related to C
741
742 template<typename T> void accept(T); // #cwg656-accept-T
743 template<typename T> void accept(...) = delete; // #cwg656-accept-var
744 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
745 void f() {
746 accept<const A&>(x);
747 accept<const A&>(y);
748 // expected-error@-1 {{cannot cast 'const Y' to its private base class 'const cwg656::A'}}
749 // expected-note@#cwg656-Y {{declared private here}}
750 accept<const A&>(vy); // #cwg656-vy
751 // expected-error@-1 {{call to deleted function 'accept'}}
752 // expected-note@#cwg656-accept-var {{candidate function [with T = const cwg656::A &] has been explicitly deleted}}
753 // expected-note@#cwg656-accept-T {{candidate function template not viable: no known conversion from 'volatile Y' to 'const A &' for 1st argument}}
754 // expected-error@#cwg656-vy {{no matching constructor for initialization of 'volatile Y'}}
755 // expected-note@#cwg656-Y {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('volatile Y') would lose volatile qualifier}}
756 // expected-note@#cwg656-Y {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
757 accept<const D&>(c);
758 }
759 }
760
761 namespace cwg657 { // cwg657: partial
762 struct Abs { virtual void x() = 0; }; // #cwg657-Abs
763 struct Der : public Abs { virtual void x(); };
764
765 struct Cnvt { template<typename F> Cnvt(F); };
766
767 void foo(Cnvt a);
768 void foo(Abs &a);
769 void f(Abs *a) { foo(*a); }
770
771 void bar(Abs &a);
772 template<typename T> void bar(T);
773 void g(Abs *a) { bar(*a); }
774
775 // FIXME: The following examples demonstrate that we might be accepting the
776 // above cases for the wrong reason.
777
778 struct C { C(Abs) {} };
779 // expected-error@-1 {{parameter type 'Abs' is an abstract class}}
780 // expected-note@#cwg657-Abs {{unimplemented pure virtual method 'x' in 'Abs'}}
781 struct Q { operator Abs() { __builtin_unreachable(); } } q;
782 // expected-error@-1 {{return type 'Abs' is an abstract class}}
783 #if __cplusplus >= 201703L
784 // FIXME: We should *definitely* reject this.
785 C c = Q().operator Abs();
786 #endif
787
788 template<typename F> struct Cnvt2 { Cnvt2(F); typedef int type; };
789
790 // FIXME: We should reject this.
791 void baz(Abs &a);
792 template<typename T> typename Cnvt2<T>::type baz(T);
793 void h(Abs *a) { baz(*a); }
794
795 // FIXME: We should reject this too.
796 Cnvt2<Abs>::type err;
797 }
798
799 // cwg658 is in cwg658.cpp
800
801 #if __cplusplus >= 201103L
802 namespace cwg659 { // cwg659: 3.0
803 static_assert(alignof(char) == alignof(char&), "");
804 static_assert(alignof(int) == alignof(int&), "");
805 int n = alignof(int(&)());
806 // since-cxx11-error@-1 {{invalid application of 'alignof' to a function type}}
807 struct A; // #cwg659-A
808 int m = alignof(A&);
809 // since-cxx11-error@-1 {{invalid application of 'alignof' to an incomplete type 'A'}}
810 // since-cxx11-note@#cwg659-A {{forward declaration of 'cwg659::A'}}
811 }
812 #endif
813
814 #if __cplusplus >= 201103L
815 namespace cwg660 { // cwg660: 3.0
816 enum : int { a };
817 enum class { b };
818 // since-cxx11-error@-1 {{scoped enumeration requires a name}}
819 auto x = a;
820
821 struct X {
822 enum : int { a };
823 enum class { b };
824 // since-cxx11-error@-1 {{scoped enumeration requires a name}}
825 };
826 auto y = X::a;
827 }
828 #endif
829
830 // cwg661 is in cwg661.cpp
831
832 namespace cwg662 { // cwg662: yes
833 template <typename T> void f(T t) {
834 T &tr = t;
835 T *tp = &t;
836 // expected-error@-1 {{'tp' declared as a pointer to a reference of type 'int &'}}
837 // expected-note@#cwg662-f-call {{in instantiation of function template specialization 'cwg662::f<int &>' requested here}}
838 #if __cplusplus >= 201103L
839 auto *ap = &t;
840 #endif
841 }
842 void g(int n) { f<int&>(n); } // #cwg662-f-call
843 }
844
845 namespace cwg663 { // cwg663: sup P1949
846 int ЍЎ = 123;
847 }
848
849 #if __cplusplus >= 201103L
850 namespace cwg664 { // cwg664: yes
851 struct A { A(const A&) = delete; };
852 A &&f(A &&a, int n) {
853 if (n)
854 return f(static_cast<A&&>(a), n - 1);
855 return static_cast<A&&>(a);
856 }
857 }
858 #endif
859
860 namespace cwg665 { // cwg665: 2.8
861 struct A { virtual ~A(); };
862 struct B : A {} *b;
863 struct C : private A {} *c; // #cwg665-C
864 struct D : B, C {} *d;
865
866 struct VB : virtual A {} *vb;
867 struct VC : private virtual A {} *vc; // #cwg665-VC
868 struct VD : VB, VC {} *vd;
869
870 void f() {
871 (void)dynamic_cast<A*>(b);
872 (void)dynamic_cast<A*>(c);
873 // expected-error@-1 {{cannot cast 'cwg665::C' to its private base class 'cwg665::A'}}
874 // expected-note@#cwg665-C {{declared private here}}
875 (void)dynamic_cast<A*>(d);
876 /* expected-error@-1 {{ambiguous conversion from derived class 'cwg665::D' to base class 'cwg665::A':
877 struct cwg665::D -> B -> A
878 struct cwg665::D -> C -> A}} */
879 (void)dynamic_cast<A*>(vb);
880 (void)dynamic_cast<A*>(vc); // emitting diagnostic, even though it could be valid at runtime
881 // expected-error@-1 {{cannot cast 'cwg665::VC' to its private base class 'cwg665::A'}}
882 // expected-note@#cwg665-VC {{declared private here}}
883 (void)dynamic_cast<A*>(vd);
884 }
885 }
886
887 namespace cwg666 { // cwg666: 2.8
888 struct P { friend P operator*(P, P); P(int); } p(0);
889
890 template<int> int f();
891 template<typename T> int f() {
892 T::type *p = 0;
893 // expected-error@-1 {{missing 'typename' prior to dependent type name 'Y::type'}}
894 // expected-note@#cwg666-f-Y {{in instantiation of function template specialization 'cwg666::f<cwg666::Y>' requested here}}
895 int a(T::type);
896 // expected-error@-1 {{missing 'typename' prior to dependent type name 'Y::type'}}
897 return f<T::type>();
898 // expected-error@-1 {{missing 'typename' prior to dependent type name 'Y::type'}}
899 }
900 struct X { static const int type = 0; };
901 struct Y { typedef int type; };
902 int a = f<X>();
903 int b = f<Y>(); // #cwg666-f-Y
904 }
905
906 // Triviality is entirely different in C++98.
907 #if __cplusplus >= 201103L
908 namespace cwg667 { // cwg667: 8
909 struct A {
910 A() = default; // #cwg667-A-ctor
911 // since-cxx11-warning@-1 {{explicitly defaulted default constructor is implicitly deleted}}
912 // since-cxx11-note@#cwg667-r {{default constructor of 'A' is implicitly deleted because field 'r' of reference type 'int &' would not be initialized}}
913 // since-cxx11-note@#cwg667-A-ctor {{replace 'default' with 'delete'}}
914 int &r; // #cwg667-r
915 };
916 static_assert(!__is_trivially_constructible(A), "");
917
918 struct B { ~B() = delete; };
919 union C { B b; };
920 static_assert(!__is_trivially_destructible(C), "");
921
922 struct D { D(const D&) = delete; };
923 struct E : D {};
924 static_assert(!__is_trivially_constructible(E, const E&), "");
925
926 struct F { F &operator=(F&&) = delete; };
927 struct G : F {};
928 static_assert(!__is_trivially_assignable(G, G&&), "");
929 }
930 #endif
931
932 // cwg668 needs an libc++abi test
933
934 #if __cplusplus >= 201103L
935 namespace cwg669 { // cwg669: yes
936 void f() {
937 int n;
938 using T = decltype(n);
939 using T = int;
940 using U = decltype((n));
941 using U = int &;
942
943 [=] {
944 using V = decltype(n);
945 using V = int;
946 using W = decltype((n));
947 using W = const int&;
948 } ();
949
950 struct X {
951 int n;
952 void f() const {
953 using X = decltype(n);
954 using X = int;
955 using Y = decltype((n));
956 using Y = const int&;
957 }
958 };
959 }
960 }
961 #endif
962
963 namespace cwg671 { // cwg671: 2.9
964 enum class E { e };
965 // cxx98-error@-1 {{scoped enumerations are a C++11 extension}}
966 E e = static_cast<E>(0);
967 int n = static_cast<int>(E::e);
968 // cxx98-error@-1 {{use of enumeration in a nested name specifier is a C++11 extension}}
969 int m = static_cast<int>(e);
970 }
971
972 // cwg672 is in cwg672.cpp
973
974 namespace cwg673 { // cwg673: yes
975 template<typename> struct X { static const int n = 0; };
976
977 class A {
978 friend class B *f();
979 class C *f();
980 void f(class D *);
981 enum { e = X<struct E>::n };
982 void g() { extern struct F *p; }
983 };
984 B *b;
985 C *c;
986 D *d;
987 E *e;
988 F *f;
989 // expected-error@-1 {{unknown type name 'F'}}
990 }
991
992 namespace cwg674 { // cwg674: 8
993 template<typename T> int f(T);
994
995 int g(int);
996 template<typename T> int g(T);
997
998 int h(int);
999 template<typename T> int h(T);
1000
1001 class X {
1002 friend int cwg674::f(int);
1003 friend int cwg674::g(int);
1004 friend int cwg674::h<>(int);
1005 int n; // #cwg674-X-n
1006 };
1007
1008 template<typename T> int f(T) { return X().n; }
1009 int g(int) { return X().n; }
1010 template<typename T> int g(T) { return X().n; }
1011 // expected-error@-1 {{'n' is a private member of 'cwg674::X'}}
1012 // expected-note@#cwg674-g-int {{in instantiation of function template specialization 'cwg674::g<int>' requested here}}
1013 // expected-note@#cwg674-X-n {{implicitly declared private here}}
1014 int h(int) { return X().n; }
1015 // expected-error@-1 {{'n' is a private member of 'cwg674::X'}}
1016 // expected-note@#cwg674-X-n {{implicitly declared private here}}
1017 template<typename T> int h(T) { return X().n; }
1018
1019 template int f(int);
1020 template int g(int); // #cwg674-g-int
1021 template int h(int);
1022
1023
1024 struct Y {
1025 template<typename T> int f(T);
1026
1027 int g(int);
1028 template<typename T> int g(T);
1029
1030 int h(int);
1031 template<typename T> int h(T);
1032 };
1033
1034 class Z {
1035 friend int Y::f(int);
1036 friend int Y::g(int);
1037 friend int Y::h<>(int);
1038 int n; // #cwg674-Z-n
1039 };
1040
1041 template<typename T> int Y::f(T) { return Z().n; }
1042 int Y::g(int) { return Z().n; }
1043 template<typename T> int Y::g(T) { return Z().n; }
1044 // expected-error@-1 {{'n' is a private member of 'cwg674::Z'}}
1045 // expected-note@#cwg674-Y-g-int {{in instantiation of function template specialization 'cwg674::Y::g<int>' requested here}}
1046 // expected-note@#cwg674-Z-n {{implicitly declared private here}}
1047 int Y::h(int) { return Z().n; }
1048 // expected-error@-1 {{'n' is a private member of 'cwg674::Z'}}
1049 // expected-note@#cwg674-Z-n {{implicitly declared private here}}
1050 template<typename T> int Y::h(T) { return Z().n; }
1051
1052 // FIXME: Should the <> be required here?
1053 template int Y::f<>(int);
1054 template int Y::g<>(int); // #cwg674-Y-g-int
1055 template int Y::h<>(int);
1056 }
1057
1058 namespace cwg675 { // cwg675: dup 739
1059 template<typename T> struct A { T n : 1; };
1060 #if __cplusplus >= 201103L
1061 static_assert(A<char>{1}.n < 0, "");
1062 // since-cxx11-warning@-1 {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}
1063 static_assert(A<int>{1}.n < 0, "");
1064 // since-cxx11-warning@-1 {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}
1065 static_assert(A<long long>{1}.n < 0, "");
1066 // since-cxx11-warning@-1 {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}
1067 #endif
1068 }
1069
1070 // cwg676: na
1071
1072 namespace cwg677 { // cwg677: no
1073 struct A {
1074 void *operator new(std::size_t);
1075 void operator delete(void*) = delete; // #cwg677-A-delete
1076 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
1077 };
1078 struct B {
1079 void *operator new(std::size_t);
1080 void operator delete(void*) = delete; // #cwg677-B-delete
1081 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
1082 virtual ~B();
1083 };
1084 void f(A *p) { delete p; }
1085 // expected-error@-1 {{attempt to use a deleted function}}
1086 // expected-note@#cwg677-A-delete {{'operator delete' has been explicitly marked deleted here}}
1087 // FIXME: This appears to be valid; we shouldn't even be looking up the 'operator delete' here.
1088 void f(B *p) { delete p; }
1089 // expected-error@-1 {{attempt to use a deleted function}}
1090 // expected-note@#cwg677-B-delete {{'operator delete' has been explicitly marked deleted here}}
1091 B::~B() {}
1092 // expected-error@-1 {{attempt to use a deleted function}}
1093 // expected-note@#cwg677-B-delete {{'operator delete' has been explicitly marked deleted here}}
1094 }
1095
1096 // cwg678 FIXME: check that the modules ODR check catches this
1097
1098 namespace cwg679 { // cwg679: yes
1099 struct X {};
1100 template<int> void operator+(X, X);
1101 template<> void operator+<0>(X, X) {} // #cwg679-def
1102 template<> void operator+<0>(X, X) {}
1103 // expected-error@-1 {{redefinition of 'operator+<0>'}}
1104 // expected-note@#cwg679-def {{previous definition is here}}
1105 }
1106
1107 // cwg680: na
1108
1109 #if __cplusplus >= 201103L
1110 namespace cwg681 { // cwg681: partial
1111 auto *a() -> int;
1112 // since-cxx11-error@-1 {{function with trailing return type must specify return type 'auto', not 'auto *'}}
1113 auto (*b)() -> int;
1114 // FIXME: The errors here aren't great.
1115 auto (*c()) -> int;
1116 // since-cxx11-error@-1 {{expected function body after function declarator}}
1117 auto ((*d)()) -> int;
1118 // since-cxx11-error@-1 {{declaration of variable 'd' with deduced type 'auto ((*)())' requires an initializer}}
1119 // since-cxx11-error@-2 {{expected ';' after top level declarator}}
1120
1121 // FIXME: This is definitely wrong. This should be
1122 // "function of () returning pointer to function of () returning int"
1123 // not a function with a deduced return type.
1124 auto (*e())() -> int;
1125 // cxx11-error@-1 {{'auto' return without trailing return type; deduced return types are a C++14 extension}}
1126
1127 auto f() -> int (*)();
1128 auto g() -> auto (*)() -> int;
1129 }
1130 #endif
1131
1132 #if __cplusplus >= 201103L
1133 namespace cwg683 { // cwg683: yes
1134 struct A {
1135 A() = default;
1136 A(const A&) = default;
1137 A(A&);
1138 };
1139 static_assert(__is_trivially_constructible(A, const A&), "");
1140 static_assert(!__is_trivially_constructible(A, A&), "");
1141 static_assert(!__is_trivial(A), "");
1142
1143 struct B : A {};
1144 static_assert(__is_trivially_constructible(B, const B&), "");
1145 static_assert(__is_trivially_constructible(B, B&), "");
1146 static_assert(__is_trivial(B), "");
1147 }
1148 #endif
1149
1150 #if __cplusplus >= 201103L
1151 namespace cwg684 { // cwg684: sup 1454
1152 void f() {
1153 int a; // #cwg684-a
1154 constexpr int *p = &a;
1155 // expected-error@-1 {{constexpr variable 'p' must be initialized by a constant expression}}
1156 // expected-note@-2 {{pointer to 'a' is not a constant expression}}
1157 // expected-note@#cwg684-a {{here}}
1158 }
1159 }
1160 #endif
1161
1162 namespace cwg685 { // cwg685: yes
1163 enum E : long { e };
1164 // cxx98-error@-1 {{enumeration types with a fixed underlying type are a C++11 extension}}
1165 void f(int);
1166 int f(long);
1167 int a = f(e);
1168
1169 enum G : short { g };
1170 // cxx98-error@-1 {{enumeration types with a fixed underlying type are a C++11 extension}}
1171 int h(short);
1172 void h(long);
1173 int b = h(g);
1174
1175 int i(int);
1176 void i(long);
1177 int c = i(g);
1178
1179 int j(unsigned int); // #cwg685-j-uint
1180 void j(long); // #cwg685-j-long
1181 int d = j(g);
1182 // expected-error@-1 {{call to 'j' is ambiguous}}
1183 // expected-note@#cwg685-j-uint {{candidate function}}
1184 // expected-note@#cwg685-j-long {{candidate function}}
1185
1186 // Valid per cwg1601
1187 int k(short);
1188 void k(int);
1189 int x = k(g);
1190 }
1191
1192 namespace cwg686 { // cwg686: 3.0
1193 void f() {
1194 (void)dynamic_cast<struct A*>(0);
1195 // expected-error@-1 {{'A' is an incomplete type}}
1196 // expected-note@-2 {{forward declaration of 'A'}}
1197 (void)dynamic_cast<struct A{}*>(0);
1198 // expected-error@-1 {{'A' cannot be defined in a type specifier}}
1199 (void)typeid(struct B*);
1200 (void)typeid(struct B{}*);
1201 // expected-error@-1 {{'B' cannot be defined in a type specifier}}
1202 (void)static_cast<struct C*>(0);
1203 (void)static_cast<struct C{}*>(0);
1204 // expected-error@-1 {{'C' cannot be defined in a type specifier}}
1205 (void)reinterpret_cast<struct D*>(0);
1206 (void)reinterpret_cast<struct D{}*>(0);
1207 // expected-error@-1 {{'D' cannot be defined in a type specifier}}
1208 (void)const_cast<struct E*>(0);
1209 // expected-error@-1 {{const_cast from 'int' to 'struct E *' is not allowed}}
1210 (void)const_cast<struct E{}*>(0);
1211 // expected-error@-1 {{'E' cannot be defined in a type specifier}}
1212 (void)sizeof(struct F*);
1213 (void)sizeof(struct F{}*);
1214 // expected-error@-1 {{'F' cannot be defined in a type specifier}}
1215 (void)new struct G*; // #cwg686-G
1216 (void)new struct G{}*; // #cwg686-G-def
1217 // expected-error@-1 {{allocation of incomplete type 'struct G'}}
1218 // expected-note@#cwg686-G {{forward declaration of 'G'}}
1219 // since-cxx11-error@#cwg686-G-def {{expected expression}}
1220 #if __cplusplus >= 201103L
1221 (void)alignof(struct H*);
1222 (void)alignof(struct H{}*);
1223 // since-cxx11-error@-1 {{'H' cannot be defined in a type specifier}}
1224 #endif
1225 (void)(struct I*)0;
1226 (void)(struct I{}*)0;
1227 // expected-error@-1 {{'I' cannot be defined in a type specifier}}
1228 if (struct J *p = 0) {}
1229 if (struct J {} *p = 0) {}
1230 // expected-error@-1 {{'J' cannot be defined in a condition}}
1231 for (struct K *p = 0; struct L *q = 0; ) {}
1232 for (struct K {} *p = 0; struct L {} *q = 0; ) {}
1233 // expected-error@-1 {{'L' cannot be defined in a condition}}
1234 #if __cplusplus >= 201103L
1235 using M = struct {};
1236 #endif
1237 struct N {
1238 operator struct O{}(){};
1239 // expected-error@-1 {{'N::O' cannot be defined in a type specifier}}
1240 };
1241 try {}
1242 catch (struct P *) {}
1243 // expected-error@-1 {{cannot catch pointer to incomplete type 'struct P'}}
1244 // expected-note@-2 {{forward declaration of 'P'}}
1245 catch (struct P {} *) {}
1246 // expected-error@-1 {{'P' cannot be defined in a type specifier}}
1247 #if __cplusplus < 201703L
1248 void g() throw(struct Q);
1249 // cxx98-17-error@-1 {{incomplete type 'struct Q' is not allowed in exception specification}}
1250 // cxx98-17-note@-2 {{forward declaration of 'Q'}}
1251 void h() throw(struct Q {});
1252 // cxx98-17-error@-1 {{'Q' cannot be defined in a type specifier}}
1253 #endif
1254 }
1255 template<struct R *> struct X;
1256 template<struct R {} *> struct Y;
1257 // expected-error@-1 {{'cwg686::R' cannot be defined in a type specifier}}
1258 }
1259
1260 namespace cwg687 { // cwg687 (9 c++20, but the issue is still considered open)
1261 template<typename T> void f(T a) {
1262 // This is valid in C++20.
1263 g<int>(a);
1264 // cxx98-17-error@-1 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}
1265
1266 // This is not.
1267 template g<int>(a);
1268 // expected-error@-1 {{expected expression}}
1269 }
1270 }
1271
1272 namespace cwg692 { // cwg692: 16
1273 // Also see cwg1395.
1274
1275 namespace temp_func_order_example2 {
1276 template <typename... T> struct A1 {};
1277 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1278 template <typename U, typename... T> struct A2 {};
1279 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1280 template <typename T1, typename... U> void e1(A1<T1, U...>) = delete;
1281 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1282 // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}
1283 template <typename T1> void e1(A1<T1>);
1284 template <typename T1, typename... U> void e2(A2<T1, U...>) = delete;
1285 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1286 // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}
1287 template <typename T1> void e2(A2<T1>);
1288 template <typename T, typename U> void f(U, A1<U, T> *p = 0) = delete; // #cwg692-f-deleted
1289 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
1290 template <typename U> int &f(U, A1<U, U> *p = 0); // #cwg692-f
1291 template <typename T> void g(T, T = T()); // #cwg692-g
1292 template <typename T, typename... U> void g(T, U...); // #cwg692-g-variadic
1293 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1294 void h() {
1295 A1<int, int> a;
1296 int &r = f<int>(42, &a);
1297 A1<int> b1;
1298 e1(b1);
1299 A2<int> b2;
1300 e2(b2);
1301 f<int>(42);
1302 // expected-error@-1 {{call to 'f' is ambiguous}}
1303 // expected-note@#cwg692-f-deleted {{candidate function [with T = int, U = int] has been explicitly deleted}}
1304 // expected-note@#cwg692-f {{candidate function [with U = int]}}
1305 g(42);
1306 // expected-error@-1 {{ambiguous}}
1307 // expected-note@#cwg692-g {{candidate function [with T = int]}}
1308 // expected-note@#cwg692-g-variadic {{candidate function [with T = int, U = <>]}}
1309 }
1310 }
1311
1312 namespace temp_func_order_example3 {
1313 template <typename T, typename... U> void f(T, U...);
1314 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1315 template <typename T> void f(T);
1316 template <typename T, typename... U> int &g(T *, U...);
1317 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1318 template <typename T> void g(T);
1319 void h(int i) {
1320 // This is made ambiguous by cwg692, but made valid again by cwg1395.
1321 f(&i);
1322 int &r = g(&i);
1323 }
1324 }
1325
1326 namespace temp_deduct_partial_example {
1327 template <typename... Args> char &f(Args... args);
1328 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1329 template <typename T1, typename... Args> short &f(T1 a1, Args... args);
1330 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1331 template <typename T1, typename T2> int &f(T1 a1, T2 a2);
1332 void g() {
1333 char &a = f();
1334 short &b = f(1, 2, 3);
1335 int &c = f(1, 2);
1336 }
1337 }
1338
1339 namespace temp_deduct_type_example1 {
1340 template <class T1, class ...Z> class S;
1341 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1342 template <class T1, class ...Z> class S<T1, const Z&...>;
1343 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1344 template <class T1, class T2> class S<T1, const T2&> {};
1345 S<int, const int&> s;
1346
1347 template<class T, class... U> struct A;
1348 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1349 template<class T1, class T2, class... U> struct A<T1,T2*,U...> {};
1350 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1351 template<class T1, class T2> struct A<T1,T2>;
1352 template struct A<int, int*>;
1353 }
1354
1355 namespace temp_deduct_type_example3 {
1356 template<class T, class... U> void f(T*, U...){}
1357 // cxx98-error@-1 {{variadic templates are a C++11 extension}}
1358 template<class T> void f(T){}
1359 template void f(int*);
1360 }
1361 }
1362
1363 namespace cwg696 { // cwg696: 3.1
1364 void f(const int*);
1365 void g() {
1366 const int N = 10; // #cwg696-N
1367 struct A {
1368 void h() {
1369 int arr[N]; (void)arr;
1370 f(&N);
1371 // expected-error@-1 {{reference to local variable 'N' declared in enclosing function 'cwg696::g'}}
1372 // expected-note@#cwg696-N {{'N' declared here}}
1373 }
1374 };
1375 #if __cplusplus >= 201103L
1376 (void) [] { int arr[N]; (void)arr; };
1377 (void)[] { f(&N); };
1378 // since-cxx11-error@-1 {{variable 'N' cannot be implicitly captured in a lambda with no capture-default specified}}
1379 // since-cxx11-note@#cwg696-N {{'N' declared here}}
1380 // since-cxx11-note@-3 {{lambda expression begins here}}
1381 // since-cxx11-note@-4 {{capture 'N' by value}}
1382 // since-cxx11-note@-5 {{capture 'N' by reference}}
1383 // since-cxx11-note@-6 {{default capture by value}}
1384 // since-cxx11-note@-7 {{default capture by reference}}
1385 #endif
1386 }
1387 }