1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 
7 // PR13819 -- __SIZE_TYPE__ is incompatible.
8 typedef __SIZE_TYPE__ size_t; // expected-error 0-1 {{extension}}
9 
10 #if __cplusplus < 201103L
11 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
12 #else
13 #define fold
14 #endif
15 
16 namespace dr200 { // dr200: dup 214
17   template <class T> T f(int);
18   template <class T, class U> T f(U) = delete; // expected-error 0-1{{extension}}
19 
g()20   void g() {
21     f<int>(1);
22   }
23 }
24 
25 // dr201 FIXME: write codegen test
26 
27 namespace dr202 { // dr202: yes
28   template<typename T> T f();
29   template<int (*g)()> struct X {
30     int arr[fold(g == &f<int>) ? 1 : -1];
31   };
32   template struct X<f>;
33 }
34 
35 // FIXME (export) dr204: no
36 
37 namespace dr206 { // dr206: yes
38   struct S; // expected-note 2{{declaration}}
39   template<typename T> struct Q { S s; }; // expected-error {{incomplete}}
f()40   template<typename T> void f() { S s; } // expected-error {{incomplete}}
41 }
42 
43 namespace dr207 { // dr207: yes
44   class A {
45   protected:
f()46     static void f() {}
47   };
48   class B : A {
49   public:
50     using A::f;
g()51     void g() {
52       A::f();
53       f();
54     }
55   };
56 }
57 
58 // dr208 FIXME: write codegen test
59 
60 namespace dr209 { // dr209: yes
61   class A {
62     void f(); // expected-note {{here}}
63   };
64   class B {
65     friend void A::f(); // expected-error {{private}}
66   };
67 }
68 
69 // dr210 FIXME: write codegen test
70 
71 namespace dr211 { // dr211: yes
72   struct A {
Adr211::A73     A() try {
74       throw 0;
75     } catch (...) {
76       return; // expected-error {{return in the catch of a function try block of a constructor}}
77     }
78   };
79 }
80 
81 namespace dr213 { // dr213: yes
82   template <class T> struct A : T {
hdr213::A83     void h(T t) {
84       char &r1 = f(t);
85       int &r2 = g(t); // expected-error {{undeclared}}
86     }
87   };
88   struct B {
89     int &f(B);
90     int &g(B); // expected-note {{in dependent base class}}
91   };
92   char &f(B);
93 
94   template void A<B>::h(B); // expected-note {{instantiation}}
95 }
96 
97 namespace dr214 { // dr214: yes
98   template<typename T, typename U> T checked_cast(U from) { U::error; }
99   template<typename T, typename U> T checked_cast(U *from);
100   class C {};
foo(int * arg)101   void foo(int *arg) { checked_cast<const C *>(arg); }
102 
103   template<typename T> T f(int);
104   template<typename T, typename U> T f(U) { T::error; }
g()105   void g() {
106     f<int>(1);
107   }
108 }
109 
110 namespace dr215 { // dr215: yes
111   template<typename T> class X {
112     friend void T::foo();
113     int n;
114   };
115   struct Y {
foodr215::Y116     void foo() { (void)+X<Y>().n; }
117   };
118 }
119 
120 namespace dr216 { // dr216: no
121   // FIXME: Should reject this: 'f' has linkage but its type does not,
122   // and 'f' is odr-used but not defined in this TU.
123   typedef enum { e } *E;
124   void f(E);
g(E e)125   void g(E e) { f(e); }
126 
127   struct S {
128     // FIXME: Should reject this: 'f' has linkage but its type does not,
129     // and 'f' is odr-used but not defined in this TU.
130     typedef enum { e } *E;
131     void f(E);
132   };
g(S s,S::E e)133   void g(S s, S::E e) { s.f(e); }
134 }
135 
136 namespace dr217 { // dr217: yes
137   template<typename T> struct S {
138     void f(int);
139   };
f(int=0)140   template<typename T> void S<T>::f(int = 0) {} // expected-error {{default arguments cannot be added}}
141 }
142 
143 namespace dr218 { // dr218: yes
144   namespace A {
145     struct S {};
146     void f(S);
147   }
148   namespace B {
149     struct S {};
150     void f(S);
151   }
152 
153   struct C {
154     int f;
test1dr218::C155     void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}}
test2dr218::C156     void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}}
test3dr218::C157     void test3(A::S as) { using A::f; f(as); } // ok
test4dr218::C158     void test4(A::S as) { using B::f; f(as); } // ok
test5dr218::C159     void test5(A::S as) { int f; f(as); } // expected-error {{called object type 'int'}}
test6dr218::C160     void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no matching conversion}} expected-note +{{}}
161   };
162 
163   namespace D {
164     struct S {};
165     struct X { void operator()(S); } f;
166   }
testD(D::S ds)167   void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
168 
169   namespace E {
170     struct S {};
171     struct f { f(S); };
172   }
testE(E::S es)173   void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
174 
175   namespace F {
176     struct S {
f(S,T)177       template<typename T> friend void f(S, T) {}
178     };
179   }
testF(F::S fs)180   void testF(F::S fs) { f(fs, 0); }
181 
182   namespace G {
183     namespace X {
184       int f;
185       struct A {};
186     }
187     namespace Y {
188       template<typename T> void f(T);
189       struct B {};
190     }
191     template<typename A, typename B> struct C {};
192   }
testG(G::C<G::X::A,G::Y::B> gc)193   void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }
194 }
195 
196 // dr219: na
197 // dr220: na
198 
199 namespace dr221 { // dr221: yes
200   struct A { // expected-note 2-4{{candidate}}
201     A &operator=(int&); // expected-note 2{{candidate}}
202     A &operator+=(int&);
203     static A &operator=(A&, double&); // expected-error {{cannot be a static member}}
204     static A &operator+=(A&, double&); // expected-error {{cannot be a static member}}
205     friend A &operator=(A&, char&); // expected-error {{must be a non-static member function}}
206     friend A &operator+=(A&, char&);
207   };
208   A &operator=(A&, float&); // expected-error {{must be a non-static member function}}
209   A &operator+=(A&, float&);
210 
test(A a,int n,char c,float f)211   void test(A a, int n, char c, float f) {
212     a = n;
213     a += n;
214     a = c; // expected-error {{no viable}}
215     a += c;
216     a = f; // expected-error {{no viable}}
217     a += f;
218   }
219 }
220 
221 namespace dr222 { // dr222: dup 637
f(int a,int b,int c,int * x)222   void f(int a, int b, int c, int *x) {
223 #pragma clang diagnostic push
224 #pragma clang diagnostic warning "-Wunsequenced"
225     void((a += b) += c);
226     void((a += b) + (a += c)); // expected-warning {{multiple unsequenced modifications to 'a'}}
227 
228     x[a++] = a;
229 #if __cplusplus < 201703L
230     // expected-warning@-2 {{unsequenced modification and access to 'a'}}
231 #endif
232 
233     a = b = 0; // ok, read and write of 'b' are sequenced
234 
235     a = (b = a++);
236 #if __cplusplus < 201703L
237     // expected-warning@-2 {{multiple unsequenced modifications to 'a'}}
238 #endif
239     a = (b = ++a);
240 #pragma clang diagnostic pop
241   }
242 }
243 
244 // dr223: na
245 
246 namespace dr224 { // dr224: no
247   namespace example1 {
248     template <class T> class A {
249       typedef int type;
250       A::type a;
251       A<T>::type b;
252       A<T*>::type c; // expected-error {{missing 'typename'}}
253       ::dr224::example1::A<T>::type d;
254 
255       class B {
256         typedef int type;
257 
258         A::type a;
259         A<T>::type b;
260         A<T*>::type c; // expected-error {{missing 'typename'}}
261         ::dr224::example1::A<T>::type d;
262 
263         B::type e;
264         A<T>::B::type f;
265         A<T*>::B::type g; // expected-error {{missing 'typename'}}
266         typename A<T*>::B::type h;
267       };
268     };
269 
270     template <class T> class A<T*> {
271       typedef int type;
272       A<T*>::type a;
273       A<T>::type b; // expected-error {{missing 'typename'}}
274     };
275 
276     template <class T1, class T2, int I> struct B {
277       typedef int type;
278       B<T1, T2, I>::type b1;
279       B<T2, T1, I>::type b2; // expected-error {{missing 'typename'}}
280 
281       typedef T1 my_T1;
282       static const int my_I = I;
283       static const int my_I2 = I+0;
284       static const int my_I3 = my_I;
285       B<my_T1, T2, my_I>::type b3; // FIXME: expected-error {{missing 'typename'}}
286       B<my_T1, T2, my_I2>::type b4; // expected-error {{missing 'typename'}}
287       B<my_T1, T2, my_I3>::type b5; // FIXME: expected-error {{missing 'typename'}}
288     };
289   }
290 
291   namespace example2 {
292     template <int, typename T> struct X { typedef T type; };
293     template <class T> class A {
294       static const int i = 5;
295       X<i, int>::type w; // FIXME: expected-error {{missing 'typename'}}
296       X<A::i, char>::type x; // FIXME: expected-error {{missing 'typename'}}
297       X<A<T>::i, double>::type y; // FIXME: expected-error {{missing 'typename'}}
298       X<A<T*>::i, long>::type z; // expected-error {{missing 'typename'}}
299       int f();
300     };
f()301     template <class T> int A<T>::f() {
302       return i;
303     }
304   }
305 }
306 
307 // dr225: yes
dr225_f(T t)308 template<typename T> void dr225_f(T t) { dr225_g(t); } // expected-error {{call to function 'dr225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}
309 void dr225_g(int); // expected-note {{should be declared prior to the call site}}
310 template void dr225_f(int); // expected-note {{in instantiation of}}
311 
312 namespace dr226 { // dr226: no
f()313   template<typename T = void> void f() {}
314 #if __cplusplus < 201103L
315   // expected-error@-2 {{extension}}
316   // FIXME: This appears to be wrong: default arguments for function templates
317   // are listed as a defect (in c++98) not an extension. EDG accepts them in
318   // strict c++98 mode.
319 #endif
320   template<typename T> struct S {
321     template<typename U = void> void g();
322 #if __cplusplus < 201103L
323   // expected-error@-2 {{extension}}
324 #endif
325     template<typename U> struct X;
326     template<typename U> void h();
327   };
g()328   template<typename T> template<typename U> void S<T>::g() {}
329   template<typename T> template<typename U = void> struct S<T>::X {}; // expected-error {{cannot add a default template arg}}
h()330   template<typename T> template<typename U = void> void S<T>::h() {} // expected-error {{cannot add a default template arg}}
331 
332   template<typename> void friend_h();
333   struct A {
334     // FIXME: This is ill-formed.
335     template<typename=void> struct friend_B;
336     // FIXME: f, h, and i are ill-formed.
337     //  f is ill-formed because it is not a definition.
338     //  h and i are ill-formed because they are not the only declarations of the
339     //  function in the translation unit.
340     template<typename=void> void friend_f();
friend_gdr226::A341     template<typename=void> void friend_g() {}
friend_hdr226::A342     template<typename=void> void friend_h() {}
friend_idr226::A343     template<typename=void> void friend_i() {}
344 #if __cplusplus < 201103L
345   // expected-error@-5 {{extension}} expected-error@-4 {{extension}}
346   // expected-error@-4 {{extension}} expected-error@-3 {{extension}}
347 #endif
348   };
349   template<typename> void friend_i();
350 
foo(X)351   template<typename=void, typename X> void foo(X) {}
352   template<typename=void, typename X> struct Foo {}; // expected-error {{missing a default argument}} expected-note {{here}}
353 #if __cplusplus < 201103L
354   // expected-error@-3 {{extension}}
355 #endif
356 
357   template<typename=void, typename X, typename, typename Y> int foo(X, Y);
358   template<typename, typename X, typename=void, typename Y> int foo(X, Y);
359   int x = foo(0, 0);
360 #if __cplusplus < 201103L
361   // expected-error@-4 {{extension}}
362   // expected-error@-4 {{extension}}
363 #endif
364 }
365 
dr227(bool b)366 void dr227(bool b) { // dr227: yes
367   if (b)
368     int n;
369   else
370     int n;
371 }
372 
373 namespace dr228 { // dr228: yes
374   template <class T> struct X {
375     void f();
376   };
377   template <class T> struct Y {
gdr228::Y378     void g(X<T> x) { x.template X<T>::f(); }
379   };
380 }
381 
382 namespace dr229 { // dr229: yes
383   template<typename T> void f();
f()384   template<typename T> void f<T*>() {} // expected-error {{function template partial specialization}}
f()385   template<> void f<int>() {}
386 }
387 
388 namespace dr230 { // dr230: yes
389   struct S {
Sdr230::S390     S() { f(); } // expected-warning {{call to pure virtual member function}}
391     virtual void f() = 0; // expected-note {{declared here}}
392   };
393 }
394 
395 namespace dr231 { // dr231: yes
396   namespace outer {
397     namespace inner {
398       int i; // expected-note {{here}}
399     }
f()400     void f() { using namespace inner; }
401     int j = i; // expected-error {{undeclared identifier 'i'; did you mean 'inner::i'?}}
402   }
403 }
404 
405 // dr234: na
406 // dr235: na
407 
408 namespace dr236 { // dr236: yes
409   void *p = int();
410 #if __cplusplus < 201103L
411   // expected-warning@-2 {{null pointer}}
412 #else
413   // expected-error@-4 {{cannot initialize}}
414 #endif
415 }
416 
417 namespace dr237 { // dr237: dup 470
fdr237::A418   template<typename T> struct A { void f() { T::error; } };
419   template<typename T> struct B : A<T> {};
420   template struct B<int>; // ok
421 }
422 
423 namespace dr239 { // dr239: yes
424   namespace NS {
425     class T {};
426     void f(T);
427     float &g(T, int);
428   }
429   NS::T parm;
430   int &g(NS::T, float);
main()431   int main() {
432     f(parm);
433     float &r = g(parm, 1);
434     extern int &g(NS::T, float);
435     int &s = g(parm, 1);
436   }
437 }
438 
439 // dr240: dup 616
440 
441 namespace dr241 { // dr241: yes
442   namespace A {
443     struct B {};
444     template <int X> void f(); // expected-note 3{{candidate}}
445     template <int X> void g(B);
446   }
447   namespace C {
448     template <class T> void f(T t); // expected-note 2{{candidate}}
449     template <class T> void g(T t); // expected-note {{candidate}}
450   }
h(A::B b)451   void h(A::B b) {
452     f<3>(b); // expected-error 0-1{{C++20 extension}} expected-error {{no matching}}
453     g<3>(b); // expected-error 0-1{{C++20 extension}}
454     A::f<3>(b); // expected-error {{no matching}}
455     A::g<3>(b);
456     C::f<3>(b); // expected-error {{no matching}}
457     C::g<3>(b); // expected-error {{no matching}}
458     using C::f;
459     using C::g;
460     f<3>(b); // expected-error {{no matching}}
461     g<3>(b);
462   }
463 }
464 
465 namespace dr243 { // dr243: yes
466   struct B;
467   struct A {
468     A(B); // expected-note {{candidate}}
469   };
470   struct B {
471     operator A() = delete; // expected-error 0-1{{extension}} expected-note {{candidate}}
472   } b;
473   A a1(b);
474   A a2 = b; // expected-error {{ambiguous}}
475 }
476 
477 namespace dr244 { // dr244: partial
478   struct B {}; struct D : B {}; // expected-note {{here}}
479 
480   D D_object;
481   typedef B B_alias;
482   B* B_ptr = &D_object;
483 
f()484   void f() {
485     D_object.~B(); // expected-error {{expression does not match the type}}
486     D_object.B::~B();
487     B_ptr->~B();
488     B_ptr->~B_alias();
489     B_ptr->B_alias::~B();
490     // This is valid under DR244.
491     B_ptr->B_alias::~B_alias();
492     B_ptr->dr244::~B(); // expected-error {{refers to a member in namespace}}
493     B_ptr->dr244::~B_alias(); // expected-error {{refers to a member in namespace}}
494   }
495 
496   namespace N {
497     template<typename T> struct E {};
498     typedef E<int> F;
499   }
g(N::F f)500   void g(N::F f) {
501     typedef N::F G;
502     f.~G();
503     f.G::~E();
504     f.G::~F(); // expected-error {{expected the class name after '~' to name a destructor}}
505     f.G::~G();
506     // This is technically ill-formed; E is looked up in 'N::' and names the
507     // class template, not the injected-class-name of the class. But that's
508     // probably a bug in the standard.
509     f.N::F::~E();
510     // This is valid; we look up the second F in the same scope in which we
511     // found the first one, that is, 'N::'.
512     f.N::F::~F(); // FIXME: expected-error {{expected the class name after '~' to name a destructor}}
513     // This is technically ill-formed; G is looked up in 'N::' and is not found;
514     // as above, this is probably a bug in the standard.
515     f.N::F::~G();
516   }
517 }
518 
519 namespace dr245 { // dr245: yes
520   struct S {
521     enum E {}; // expected-note {{here}}
522     class E *p; // expected-error {{does not match previous declaration}}
523   };
524 }
525 
526 namespace dr246 { // dr246: yes
527   struct S {
Sdr246::S528     S() try { // expected-note {{try block}}
529       throw 0;
530 X: ;
531     } catch (int) {
532       goto X; // expected-error {{cannot jump}}
533     }
534   };
535 }
536 
537 namespace dr247 { // dr247: yes
538   struct A {};
539   struct B : A {
540     void f();
541     void f(int);
542   };
543   void (A::*f)() = (void (A::*)())&B::f;
544 
545   struct C {
546     void f();
547     void f(int);
548   };
549   struct D : C {};
550   void (C::*g)() = &D::f;
551   void (D::*h)() = &D::f;
552 
553   struct E {
554     void f();
555   };
556   struct F : E {
557     using E::f;
558     void f(int);
559   };
560   void (F::*i)() = &F::f;
561 }
562 
563 namespace dr248 { // dr248: yes c++11
564   // FIXME: Should this also apply to c++98 mode? This was a DR against C++98.
565   int \u040d\u040e = 0;
566 #if __cplusplus < 201103L
567   // FIXME: expected-error@-2 {{expected ';'}}
568 #endif
569 }
570 
571 namespace dr249 { // dr249: yes
572   template<typename T> struct X { void f(); };
f()573   template<typename T> void X<T>::f() {}
574 }
575 
576 namespace dr250 { // dr250: yes
577   typedef void (*FPtr)(double x[]);
578 
579   template<int I> void f(double x[]);
580   FPtr fp = &f<3>;
581 
582   template<int I = 3> void g(double x[]); // expected-error 0-1{{extension}}
583   FPtr gp = &g<>;
584 }
585 
586 namespace dr252 { // dr252: yes
587   struct A {
588     void operator delete(void*); // expected-note {{found}}
589   };
590   struct B {
591     void operator delete(void*); // expected-note {{found}}
592   };
593   struct C : A, B {
594     virtual ~C();
595   };
~C()596   C::~C() {} // expected-error {{'operator delete' found in multiple base classes}}
597 
598   struct D {
599     void operator delete(void*, int); // expected-note {{here}}
600     virtual ~D();
601   };
~D()602   D::~D() {} // expected-error {{no suitable member 'operator delete'}}
603 
604   struct E {
605     void operator delete(void*, int);
606     void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note 1-2 {{here}}
607     virtual ~E(); // expected-error 0-1 {{attempt to use a deleted function}}
608   };
~E()609   E::~E() {} // expected-error {{attempt to use a deleted function}}
610 
611   struct F {
612     // If both functions are available, the first one is a placement delete.
613     void operator delete(void*, size_t);
614     void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note {{here}}
615     virtual ~F();
616   };
~F()617   F::~F() {} // expected-error {{attempt to use a deleted function}}
618 
619   struct G {
620     void operator delete(void*, size_t);
621     virtual ~G();
622   };
~G()623   G::~G() {}
624 }
625 
626 namespace dr254 { // dr254: yes
627   template<typename T> struct A {
628     typedef typename T::type type; // ok even if this is a typedef-name, because
629                                    // it's not an elaborated-type-specifier
630     typedef struct T::type foo; // expected-error {{typedef 'type' cannot be referenced with a struct specifier}}
631   };
632   struct B { struct type {}; };
633   struct C { typedef struct {} type; }; // expected-note {{here}}
634   A<B>::type n;
635   A<C>::type n; // expected-note {{instantiation of}}
636 }
637 
638 // dr256: dup 624
639 
640 namespace dr257 { // dr257: yes
641   struct A { A(int); }; // expected-note {{here}}
642   struct B : virtual A {
Bdr257::B643     B() {}
644     virtual void f() = 0;
645   };
646   struct C : B {
Cdr257::C647     C() {}
648   };
649   struct D : B {
Ddr257::D650     D() {} // expected-error {{must explicitly initialize the base class 'dr257::A'}}
651     void f();
652   };
653 }
654 
655 namespace dr258 { // dr258: yes
656   struct A {
657     void f(const int);
658     template<typename> void g(int);
659     float &h() const;
660   };
661   struct B : A {
662     using A::f;
663     using A::g;
664     using A::h;
665     int &f(int);
666     template<int> int &g(int); // expected-note {{candidate}}
667     int &h();
668   } b;
669   int &w = b.f(0);
670   int &x = b.g<int>(0); // expected-error {{no match}}
671   int &y = b.h();
672   float &z = const_cast<const B&>(b).h();
673 
674   struct C {
675     virtual void f(const int) = 0;
676   };
677   struct D : C {
678     void f(int);
679   } d;
680 
681   struct E {
682     virtual void f() = 0; // expected-note {{unimplemented}}
683   };
684   struct F : E {
fdr258::F685     void f() const {}
686   } f; // expected-error {{abstract}}
687 }
688 
689 namespace dr259 { // dr259: 4
690   template<typename T> struct A {};
691   template struct A<int>; // expected-note {{previous}}
692   template struct A<int>; // expected-error {{duplicate explicit instantiation}}
693 
694   template<> struct A<float>; // expected-note {{previous}}
695   template struct A<float>; // expected-warning {{has no effect}}
696 
697   template struct A<char>; // expected-note {{here}}
698   template<> struct A<char>; // expected-error {{explicit specialization of 'dr259::A<char>' after instantiation}}
699 
700   template<> struct A<double>;
701   template<> struct A<double>;
702   template<> struct A<double> {}; // expected-note {{here}}
703   template<> struct A<double> {}; // expected-error {{redefinition}}
704 
705   template<typename T> struct B; // expected-note {{here}}
706   template struct B<int>; // expected-error {{undefined}}
707 
708   template<> struct B<float>; // expected-note {{previous}}
709   template struct B<float>; // expected-warning {{has no effect}}
710 }
711 
712 // FIXME: When dr260 is resolved, also add tests for DR507.
713 
714 namespace dr261 { // dr261: no
715 #pragma clang diagnostic push
716 #pragma clang diagnostic warning "-Wused-but-marked-unused"
717 
718   // FIXME: This is ill-formed, with a diagnostic required, because operator new
719   // and operator delete are inline and odr-used, but not defined in this
720   // translation unit.
721   // We're also missing the -Wused-but-marked-unused diagnostic here.
722   struct A {
723     inline void *operator new(size_t) __attribute__((unused));
724     inline void operator delete(void*) __attribute__((unused));
Adr261::A725     A() {}
726   };
727 
728   // FIXME: This is ill-formed, with a required diagnostic, for the same
729   // reason.
730   struct B {
731     inline void operator delete(void*) __attribute__((unused));
~Bdr261::B732     ~B() {}
733   };
734   struct C {
735     inline void operator delete(void*) __attribute__((unused));
~Cdr261::C736     virtual ~C() {} // expected-warning {{'operator delete' was marked unused but was used}}
737   };
738 
739   struct D {
740     inline void operator delete(void*) __attribute__((unused));
741   };
h()742   void h() { C::operator delete(0); } // expected-warning {{marked unused but was used}}
743 
744 #pragma clang diagnostic pop
745 }
746 
747 namespace dr262 { // dr262: yes
748   int f(int = 0, ...);
749   int k = f();
750   int l = f(0);
751   int m = f(0, 0);
752 }
753 
754 namespace dr263 { // dr263: yes
755   struct X {};
756   struct Y {
757 #if __cplusplus < 201103L
758     friend X::X() throw();
759     friend X::~X() throw();
760 #elif __cplusplus <= 201703L
761     friend constexpr X::X() noexcept;
762     friend X::~X();
763 #else
764     friend constexpr X::X() noexcept;
765     friend constexpr X::~X();
766 #endif
767     Y::Y(); // expected-error {{extra qualification}}
768     Y::~Y(); // expected-error {{extra qualification}}
769   };
770 }
771 
772 // dr265: dup 353
773 // dr266: na
774 // dr269: na
775 // dr270: na
776 
777 namespace dr272 { // dr272: yes
778   struct X {
fdr272::X779     void f() {
780       this->~X();
781       X::~X();
782       ~X(); // expected-error {{unary expression}}
783     }
784   };
785 }
786 
787 #include <stdarg.h>
788 #include <stddef.h>
789 namespace dr273 { // dr273: yes
790   struct A {
791     int n;
792   };
793   void operator&(A);
f(A a,...)794   void f(A a, ...) {
795     offsetof(A, n);
796     va_list val;
797     va_start(val, a);
798     va_end(val);
799   }
800 }
801 
802 // dr274: na
803 
804 namespace dr275 { // dr275: no
805   namespace N {
f(T)806     template <class T> void f(T) {} // expected-note 1-4{{here}}
g(T)807     template <class T> void g(T) {} // expected-note {{candidate}}
808     template <> void f(int);
809     template <> void f(char);
810     template <> void f(double);
811     template <> void g(char);
812   }
813 
814   using namespace N;
815 
816   namespace M {
f(char)817     template <> void N::f(char) {} // expected-error {{'M' does not enclose namespace 'N'}}
g(T)818     template <class T> void g(T) {}
g(char)819     template <> void g(char) {}
820     template void f(long);
821 #if __cplusplus >= 201103L
822     // FIXME: this should be rejected in c++98 too
823     // expected-error@-3 {{must occur in namespace 'N'}}
824 #endif
825     template void N::f(unsigned long);
826 #if __cplusplus >= 201103L
827     // FIXME: this should be rejected in c++98 too
828     // expected-error@-3 {{not in a namespace enclosing 'N'}}
829 #endif
830     template void h(long); // expected-error {{does not refer to a function template}}
f(double)831     template <> void f(double) {} // expected-error {{no function template matches}}
832   }
833 
g(T)834   template <class T> void g(T) {} // expected-note {{candidate}}
835 
f(char)836   template <> void N::f(char) {}
f(int)837   template <> void f(int) {} // expected-error {{no function template matches}}
838 
839   template void f(short);
840 #if __cplusplus >= 201103L
841   // FIXME: this should be rejected in c++98 too
842   // expected-error@-3 {{must occur in namespace 'N'}}
843 #endif
844   template void N::f(unsigned short);
845 
846   // FIXME: this should probably be valid. the wording from the issue
847   // doesn't clarify this, but it follows from the usual rules.
848   template void g(int); // expected-error {{ambiguous}}
849 
850   // FIXME: likewise, this should also be valid.
f(T)851   template<typename T> void f(T) {} // expected-note {{candidate}}
852   template void f(short); // expected-error {{ambiguous}}
853 }
854 
855 // dr276: na
856 
857 namespace dr277 { // dr277: yes
858   typedef int *intp;
859   int *p = intp();
860   int a[fold(intp() ? -1 : 1)];
861 }
862 
863 namespace dr280 { // dr280: yes
864   typedef void f0();
865   typedef void f1(int);
866   typedef void f2(int, int);
867   typedef void f3(int, int, int);
868   struct A {
869     operator f1*(); // expected-note {{here}} expected-note {{candidate}}
870     operator f2*();
871   };
872   struct B {
873     operator f0*(); // expected-note {{candidate}}
874   private:
875     operator f3*(); // expected-note {{here}} expected-note {{candidate}}
876   };
877   struct C {
878     operator f0*(); // expected-note {{candidate}}
879     operator f1*(); // expected-note {{candidate}}
880     operator f2*(); // expected-note {{candidate}}
881     operator f3*(); // expected-note {{candidate}}
882   };
883   struct D : private A, B { // expected-note 2{{here}}
884     operator f2*(); // expected-note {{candidate}}
885   } d;
886   struct E : C, D {} e;
g()887   void g() {
888     d(); // ok, public
889     d(0); // expected-error {{private member of 'dr280::A'}} expected-error {{private base class 'dr280::A'}}
890     d(0, 0); // ok, suppressed by member in D
891     d(0, 0, 0); // expected-error {{private member of 'dr280::B'}}
892     e(); // expected-error {{ambiguous}}
893     e(0); // expected-error {{ambiguous}}
894     e(0, 0); // expected-error {{ambiguous}}
895     e(0, 0, 0); // expected-error {{ambiguous}}
896   }
897 }
898 
899 namespace dr281 { // dr281: no
900   void a();
901   inline void b();
902 
903   void d();
904   inline void e();
905 
906   struct S {
907     friend inline void a(); // FIXME: ill-formed
908     friend inline void b();
909     friend inline void c(); // FIXME: ill-formed
d()910     friend inline void d() {}
e()911     friend inline void e() {}
f()912     friend inline void f() {}
913   };
914 }
915 
916 namespace dr283 { // dr283: yes
917   template<typename T> // expected-note 2{{here}}
918   struct S {
919     friend class T; // expected-error {{shadows}}
920     class T; // expected-error {{shadows}}
921   };
922 }
923 
924 namespace dr284 { // dr284: no
925   namespace A {
926     struct X;
927     enum Y {};
928     class Z {};
929   }
930   namespace B {
931     struct W;
932     using A::X;
933     using A::Y;
934     using A::Z;
935   }
936   struct B::V {}; // expected-error {{no struct named 'V'}}
937   struct B::W {};
938   struct B::X {}; // FIXME: ill-formed
939   enum B::Y e; // ok per dr417
940   class B::Z z; // ok per dr417
941 
942   struct C {
943     struct X;
944     enum Y {};
945     class Z {};
946   };
947   struct D : C {
948     struct W;
949     using C::X;
950     using C::Y;
951     using C::Z;
952   };
953   struct D::V {}; // expected-error {{no struct named 'V'}}
954   struct D::W {};
955   struct D::X {}; // FIXME: ill-formed
956   enum D::Y e2; // ok per dr417
957   class D::Z z2; // ok per dr417
958 }
959 
960 namespace dr285 { // dr285: yes
961   template<typename T> void f(T, int); // expected-note {{match}}
962   template<typename T> void f(int, T); // expected-note {{match}}
f(int,int)963   template<> void f<int>(int, int) {} // expected-error {{ambiguous}}
964 }
965 
966 namespace dr286 { // dr286: yes
967   template<class T> struct A {
968     class C {
969       template<class T2> struct B {}; // expected-note {{here}}
970     };
971   };
972 
973   template<class T>
974   template<class T2>
975   struct A<T>::C::B<T2*> { };
976 
977   A<short>::C::B<int*> absip; // expected-error {{private}}
978 }
979 
980 // dr288: na
981 
982 namespace dr289 { // dr289: yes
983   struct A; // expected-note {{forward}}
984   struct B : A {}; // expected-error {{incomplete}}
985 
986   template<typename T> struct C { typename T::error error; }; // expected-error {{cannot be used prior to '::'}}
987   struct D : C<int> {}; // expected-note {{instantiation}}
988 }
989 
990 // dr290: na
991 // dr291: dup 391
992 // dr292 FIXME: write a codegen test
993 
994 namespace dr294 { // dr294: no
995   void f() throw(int);
996 #if __cplusplus > 201402L
997     // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
998 #endif
main()999   int main() {
1000     (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before
1001 #if __cplusplus > 201402L
1002     // FIXME: expected-error@-2 {{not allowed}}
1003     //
1004     // Irony: the above is valid in C++17 and beyond, but that's exactly when
1005     // we reject it. In C++14 and before, this is ill-formed because an
1006     // exception-specification is not permitted in a type-id. In C++17, this is
1007     // valid because it's the inverse of a standard conversion sequence
1008     // containing a function pointer conversion. (Well, it's actually not valid
1009     // yet, as a static_cast is not permitted to reverse a function pointer
1010     // conversion, but that is being changed by core issue).
1011 #endif
1012     (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before
1013 #if __cplusplus > 201402L
1014     // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1015 #endif
1016 
1017     void (*p)() throw() = f; // expected-error-re {{{{not superset|different exception specification}}}}
1018     void (*q)() throw(int) = f;
1019 #if __cplusplus > 201402L
1020     // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1021 #endif
1022   }
1023 }
1024 
1025 namespace dr295 { // dr295: 3.7
1026   typedef int f();
1027   const f g; // expected-warning {{'const' qualifier on function type 'dr295::f' (aka 'int ()') has no effect}}
1028   f &r = g;
1029   template<typename T> struct X {
1030     const T &f;
1031   };
1032   X<f> x = {g};
1033 
1034   typedef int U();
1035   typedef const U U; // expected-warning {{'const' qualifier on function type 'dr295::U' (aka 'int ()') has no effect}}
1036 
1037   typedef int (*V)();
1038   typedef volatile U *V; // expected-warning {{'volatile' qualifier on function type 'dr295::U' (aka 'int ()') has no effect}}
1039 }
1040 
1041 namespace dr296 { // dr296: yes
1042   struct A {
operator intdr296::A1043     static operator int() { return 0; } // expected-error {{static}}
1044   };
1045 }
1046 
1047 namespace dr298 { // dr298: yes
1048   struct A {
1049     typedef int type;
1050     A();
1051     ~A();
1052   };
1053   typedef A B; // expected-note {{here}}
1054   typedef const A C; // expected-note {{here}}
1055 
1056   A::type i1;
1057   B::type i2;
1058   C::type i3;
1059 
1060   struct A a;
1061   struct B b; // expected-error {{typedef 'B' cannot be referenced with a struct specifier}}
1062   struct C c; // expected-error {{typedef 'C' cannot be referenced with a struct specifier}}
1063 
B()1064   B::B() {} // expected-error {{requires a type specifier}}
A()1065   B::A() {} // ok
~C()1066   C::~C() {} // expected-error {{destructor cannot be declared using a typedef 'dr298::C' (aka 'const dr298::A') of the class name}}
1067 
1068   typedef struct D E; // expected-note {{here}}
1069   struct E {}; // expected-error {{conflicts with typedef}}
1070 
1071   struct F {
1072     ~F();
1073   };
1074   typedef const F G;
~F()1075   G::~F() {} // ok
1076 }
1077 
1078 namespace dr299 { // dr299: yes c++11
1079   struct S {
1080     operator int();
1081   };
1082   struct T {
1083     operator int(); // expected-note {{}}
1084     operator unsigned short(); // expected-note {{}}
1085   };
1086   // FIXME: should this apply to c++98 mode?
1087   int *p = new int[S()]; // expected-error 0-1{{extension}}
1088   int *q = new int[T()]; // expected-error {{ambiguous}}
1089 }
1090