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