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 {{explicit qualification required to use member 'g' from dependent base class}}
86     }
87   };
88   struct B {
89     int &f(B);
90     int &g(B); // expected-note {{here}}
91   };
92   char &f(B);
93 
94   template void A<B>::h(B); // expected-note {{instantiation}}
95 }
96 
97 namespace dr214 { // dr214: yes
checked_cast(U from)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);
f(U)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: 11
478   struct B {}; // expected-note {{type 'dr244::B' found by destructor name lookup}}
479   struct D : B {};
480 
481   D D_object;
482   typedef B B_alias;
483   B* B_ptr = &D_object;
484 
f()485   void f() {
486     D_object.~B(); // expected-error {{does not match the type 'dr244::D' of the object being destroyed}}
487     D_object.B::~B();
488     D_object.D::~B(); // FIXME: Missing diagnostic for this.
489     B_ptr->~B();
490     B_ptr->~B_alias();
491     B_ptr->B_alias::~B();
492     B_ptr->B_alias::~B_alias();
493     B_ptr->dr244::~B(); // expected-error {{refers to a member in namespace}}
494     B_ptr->dr244::~B_alias(); // expected-error {{refers to a member in namespace}}
495   }
496 
497   template<typename T, typename U>
f(T * B_ptr,U D_object)498   void f(T *B_ptr, U D_object) {
499     D_object.~B(); // FIXME: Missing diagnostic for this.
500     D_object.B::~B();
501     D_object.D::~B(); // FIXME: Missing diagnostic for this.
502     B_ptr->~B();
503     B_ptr->~B_alias();
504     B_ptr->B_alias::~B();
505     B_ptr->B_alias::~B_alias();
506     B_ptr->dr244::~B(); // expected-error {{does not refer to a type name}}
507     B_ptr->dr244::~B_alias(); // expected-error {{does not refer to a type name}}
508   }
509   template void f<B, D>(B*, D);
510 
511   namespace N {
512     template<typename T> struct E {};
513     typedef E<int> F;
514   }
g(N::F f)515   void g(N::F f) {
516     typedef N::F G; // expected-note {{found by destructor name lookup}}
517     f.~G();
518     f.G::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
519     f.G::~F(); // expected-error {{undeclared identifier 'F' in destructor name}}
520     f.G::~G();
521     // This is technically ill-formed; E is looked up in 'N::' and names the
522     // class template, not the injected-class-name of the class. But that's
523     // probably a bug in the standard.
524     f.N::F::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
525     // This is valid; we look up the second F in the same scope in which we
526     // found the first one, that is, 'N::'.
527     f.N::F::~F();
528     // This is technically ill-formed; G is looked up in 'N::' and is not found.
529     // Rejecting this seems correct, but most compilers accept, so we do also.
530     f.N::F::~G(); // expected-error {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
531   }
532 
533   // Bizarrely, compilers perform lookup in the scope for qualified destructor
534   // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
535   // this.
536   namespace QualifiedLookupInScope {
537     namespace N {
538       template <typename> struct S { struct Inner {}; };
539     }
f(typename N::S<U>::Inner * p)540     template <typename U> void f(typename N::S<U>::Inner *p) {
541       typedef typename N::S<U>::Inner T;
542       p->::dr244::QualifiedLookupInScope::N::S<U>::Inner::~T(); // expected-error {{no type named 'T' in}}
543     }
544     template void f<int>(N::S<int>::Inner *); // expected-note {{instantiation of}}
545 
g(U * p)546     template <typename U> void g(U *p) {
547       typedef U T;
548       p->T::~T();
549       p->U::~T();
550       p->::dr244::QualifiedLookupInScope::N::S<int>::Inner::~T(); // expected-error {{'T' does not refer to a type name}}
551     }
552     template void g(N::S<int>::Inner *);
553   }
554 }
555 
556 namespace dr245 { // dr245: yes
557   struct S {
558     enum E {}; // expected-note {{here}}
559     class E *p; // expected-error {{does not match previous declaration}}
560   };
561 }
562 
563 namespace dr246 { // dr246: yes
564   struct S {
Sdr246::S565     S() try { // expected-note {{try block}}
566       throw 0;
567 X: ;
568     } catch (int) {
569       goto X; // expected-error {{cannot jump}}
570     }
571   };
572 }
573 
574 namespace dr247 { // dr247: yes
575   struct A {};
576   struct B : A {
577     void f();
578     void f(int);
579   };
580   void (A::*f)() = (void (A::*)())&B::f;
581 
582   struct C {
583     void f();
584     void f(int);
585   };
586   struct D : C {};
587   void (C::*g)() = &D::f;
588   void (D::*h)() = &D::f;
589 
590   struct E {
591     void f();
592   };
593   struct F : E {
594     using E::f;
595     void f(int);
596   };
597   void (F::*i)() = &F::f;
598 }
599 
600 namespace dr248 { // dr248: yes c++11
601   // FIXME: Should this also apply to c++98 mode? This was a DR against C++98.
602   int \u040d\u040e = 0;
603 #if __cplusplus < 201103L
604   // FIXME: expected-error@-2 {{expected ';'}}
605 #endif
606 }
607 
608 namespace dr249 { // dr249: yes
609   template<typename T> struct X { void f(); };
f()610   template<typename T> void X<T>::f() {}
611 }
612 
613 namespace dr250 { // dr250: yes
614   typedef void (*FPtr)(double x[]);
615 
616   template<int I> void f(double x[]);
617   FPtr fp = &f<3>;
618 
619   template<int I = 3> void g(double x[]); // expected-error 0-1{{extension}}
620   FPtr gp = &g<>;
621 }
622 
623 namespace dr252 { // dr252: yes
624   struct A {
625     void operator delete(void*); // expected-note {{found}}
626   };
627   struct B {
628     void operator delete(void*); // expected-note {{found}}
629   };
630   struct C : A, B {
631     virtual ~C();
632   };
~C()633   C::~C() {} // expected-error {{'operator delete' found in multiple base classes}}
634 
635   struct D {
636     void operator delete(void*, int); // expected-note {{here}}
637     virtual ~D();
638   };
~D()639   D::~D() {} // expected-error {{no suitable member 'operator delete'}}
640 
641   struct E {
642     void operator delete(void*, int);
643     void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note 1-2 {{here}}
644     virtual ~E(); // expected-error 0-1 {{attempt to use a deleted function}}
645   };
~E()646   E::~E() {} // expected-error {{attempt to use a deleted function}}
647 
648   struct F {
649     // If both functions are available, the first one is a placement delete.
650     void operator delete(void*, size_t);
651     void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note {{here}}
652     virtual ~F();
653   };
~F()654   F::~F() {} // expected-error {{attempt to use a deleted function}}
655 
656   struct G {
657     void operator delete(void*, size_t);
658     virtual ~G();
659   };
~G()660   G::~G() {}
661 }
662 
663 namespace dr254 { // dr254: yes
664   template<typename T> struct A {
665     typedef typename T::type type; // ok even if this is a typedef-name, because
666                                    // it's not an elaborated-type-specifier
667     typedef struct T::type foo; // expected-error {{typedef 'type' cannot be referenced with a struct specifier}}
668   };
669   struct B { struct type {}; };
670   struct C { typedef struct {} type; }; // expected-note {{here}}
671   A<B>::type n;
672   A<C>::type n; // expected-note {{instantiation of}}
673 }
674 
675 // dr256: dup 624
676 
677 namespace dr257 { // dr257: yes
678   struct A { A(int); }; // expected-note {{here}}
679   struct B : virtual A {
Bdr257::B680     B() {}
681     virtual void f() = 0;
682   };
683   struct C : B {
Cdr257::C684     C() {}
685   };
686   struct D : B {
Ddr257::D687     D() {} // expected-error {{must explicitly initialize the base class 'dr257::A'}}
688     void f();
689   };
690 }
691 
692 namespace dr258 { // dr258: yes
693   struct A {
694     void f(const int);
695     template<typename> void g(int);
696     float &h() const;
697   };
698   struct B : A {
699     using A::f;
700     using A::g;
701     using A::h;
702     int &f(int);
703     template<int> int &g(int); // expected-note {{candidate}}
704     int &h();
705   } b;
706   int &w = b.f(0);
707   int &x = b.g<int>(0); // expected-error {{no match}}
708   int &y = b.h();
709   float &z = const_cast<const B&>(b).h();
710 
711   struct C {
712     virtual void f(const int) = 0;
713   };
714   struct D : C {
715     void f(int);
716   } d;
717 
718   struct E {
719     virtual void f() = 0; // expected-note {{unimplemented}}
720   };
721   struct F : E {
fdr258::F722     void f() const {}
723   } f; // expected-error {{abstract}}
724 }
725 
726 namespace dr259 { // dr259: 4
727   template<typename T> struct A {};
728   template struct A<int>; // expected-note {{previous}}
729   template struct A<int>; // expected-error {{duplicate explicit instantiation}}
730 
731   template<> struct A<float>; // expected-note {{previous}}
732   template struct A<float>; // expected-warning {{has no effect}}
733 
734   template struct A<char>; // expected-note {{here}}
735   template<> struct A<char>; // expected-error {{explicit specialization of 'dr259::A<char>' after instantiation}}
736 
737   template<> struct A<double>;
738   template<> struct A<double>;
739   template<> struct A<double> {}; // expected-note {{here}}
740   template<> struct A<double> {}; // expected-error {{redefinition}}
741 
742   template<typename T> struct B; // expected-note {{here}}
743   template struct B<int>; // expected-error {{undefined}}
744 
745   template<> struct B<float>; // expected-note {{previous}}
746   template struct B<float>; // expected-warning {{has no effect}}
747 }
748 
749 // FIXME: When dr260 is resolved, also add tests for DR507.
750 
751 namespace dr261 { // dr261: no
752 #pragma clang diagnostic push
753 #pragma clang diagnostic warning "-Wused-but-marked-unused"
754 
755   // FIXME: This is ill-formed, with a diagnostic required, because operator new
756   // and operator delete are inline and odr-used, but not defined in this
757   // translation unit.
758   // We're also missing the -Wused-but-marked-unused diagnostic here.
759   struct A {
760     inline void *operator new(size_t) __attribute__((unused));
761     inline void operator delete(void*) __attribute__((unused));
Adr261::A762     A() {}
763   };
764 
765   // FIXME: This is ill-formed, with a required diagnostic, for the same
766   // reason.
767   struct B {
768     inline void operator delete(void*) __attribute__((unused));
~Bdr261::B769     ~B() {}
770   };
771   struct C {
772     inline void operator delete(void*) __attribute__((unused));
~Cdr261::C773     virtual ~C() {} // expected-warning {{'operator delete' was marked unused but was used}}
774   };
775 
776   struct D {
777     inline void operator delete(void*) __attribute__((unused));
778   };
h()779   void h() { C::operator delete(0); } // expected-warning {{marked unused but was used}}
780 
781 #pragma clang diagnostic pop
782 }
783 
784 namespace dr262 { // dr262: yes
785   int f(int = 0, ...);
786   int k = f();
787   int l = f(0);
788   int m = f(0, 0);
789 }
790 
791 namespace dr263 { // dr263: yes
792   struct X {};
793   struct Y {
794 #if __cplusplus < 201103L
795     friend X::X() throw();
796     friend X::~X() throw();
797 #elif __cplusplus <= 201703L
798     friend constexpr X::X() noexcept;
799     friend X::~X();
800 #else
801     friend constexpr X::X() noexcept;
802     friend constexpr X::~X();
803 #endif
804     Y::Y(); // expected-error {{extra qualification}}
805     Y::~Y(); // expected-error {{extra qualification}}
806   };
807 }
808 
809 // dr265: dup 353
810 // dr266: na
811 // dr269: na
812 // dr270: na
813 
814 namespace dr272 { // dr272: yes
815   struct X {
fdr272::X816     void f() {
817       this->~X();
818       X::~X();
819       ~X(); // expected-error {{unary expression}}
820     }
821   };
822 }
823 
824 #include <stdarg.h>
825 #include <stddef.h>
826 namespace dr273 { // dr273: yes
827   struct A {
828     int n;
829   };
830   void operator&(A);
f(A a,...)831   void f(A a, ...) {
832     offsetof(A, n);
833     va_list val;
834     va_start(val, a);
835     va_end(val);
836   }
837 }
838 
839 // dr274: na
840 
841 namespace dr275 { // dr275: no
842   namespace N {
f(T)843     template <class T> void f(T) {} // expected-note 1-4{{here}}
g(T)844     template <class T> void g(T) {} // expected-note {{candidate}}
845     template <> void f(int);
846     template <> void f(char);
847     template <> void f(double);
848     template <> void g(char);
849   }
850 
851   using namespace N;
852 
853   namespace M {
f(char)854     template <> void N::f(char) {} // expected-error {{'M' does not enclose namespace 'N'}}
g(T)855     template <class T> void g(T) {}
g(char)856     template <> void g(char) {}
857     template void f(long);
858 #if __cplusplus >= 201103L
859     // FIXME: this should be rejected in c++98 too
860     // expected-error@-3 {{must occur in namespace 'N'}}
861 #endif
862     template void N::f(unsigned long);
863 #if __cplusplus >= 201103L
864     // FIXME: this should be rejected in c++98 too
865     // expected-error@-3 {{not in a namespace enclosing 'N'}}
866 #endif
867     template void h(long); // expected-error {{does not refer to a function template}}
f(double)868     template <> void f(double) {} // expected-error {{no function template matches}}
869   }
870 
g(T)871   template <class T> void g(T) {} // expected-note {{candidate}}
872 
f(char)873   template <> void N::f(char) {}
f(int)874   template <> void f(int) {} // expected-error {{no function template matches}}
875 
876   template void f(short);
877 #if __cplusplus >= 201103L
878   // FIXME: this should be rejected in c++98 too
879   // expected-error@-3 {{must occur in namespace 'N'}}
880 #endif
881   template void N::f(unsigned short);
882 
883   // FIXME: this should probably be valid. the wording from the issue
884   // doesn't clarify this, but it follows from the usual rules.
885   template void g(int); // expected-error {{ambiguous}}
886 
887   // FIXME: likewise, this should also be valid.
f(T)888   template<typename T> void f(T) {} // expected-note {{candidate}}
889   template void f(short); // expected-error {{ambiguous}}
890 }
891 
892 // dr276: na
893 
894 namespace dr277 { // dr277: yes
895   typedef int *intp;
896   int *p = intp();
897   int a[fold(intp() ? -1 : 1)];
898 }
899 
900 namespace dr280 { // dr280: yes
901   typedef void f0();
902   typedef void f1(int);
903   typedef void f2(int, int);
904   typedef void f3(int, int, int);
905   struct A {
906     operator f1*(); // expected-note {{here}} expected-note {{candidate}}
907     operator f2*();
908   };
909   struct B {
910     operator f0*(); // expected-note {{candidate}}
911   private:
912     operator f3*(); // expected-note {{here}} expected-note {{candidate}}
913   };
914   struct C {
915     operator f0*(); // expected-note {{candidate}}
916     operator f1*(); // expected-note {{candidate}}
917     operator f2*(); // expected-note {{candidate}}
918     operator f3*(); // expected-note {{candidate}}
919   };
920   struct D : private A, B { // expected-note {{here}}
921     operator f2*(); // expected-note {{candidate}}
922   } d;
923   struct E : C, D {} e;
g()924   void g() {
925     d(); // ok, public
926     d(0); // expected-error {{private member of 'dr280::A'}}
927     d(0, 0); // ok, suppressed by member in D
928     d(0, 0, 0); // expected-error {{private member of 'dr280::B'}}
929     e(); // expected-error {{ambiguous}}
930     e(0); // expected-error {{ambiguous}}
931     e(0, 0); // expected-error {{ambiguous}}
932     e(0, 0, 0); // expected-error {{ambiguous}}
933   }
934 }
935 
936 namespace dr281 { // dr281: no
937   void a();
938   inline void b();
939 
940   void d();
941   inline void e();
942 
943   struct S {
944     friend inline void a(); // FIXME: ill-formed
945     friend inline void b();
946     friend inline void c(); // FIXME: ill-formed
d()947     friend inline void d() {}
e()948     friend inline void e() {}
f()949     friend inline void f() {}
950   };
951 }
952 
953 namespace dr283 { // dr283: yes
954   template<typename T> // expected-note 2{{here}}
955   struct S {
956     friend class T; // expected-error {{shadows}}
957     class T; // expected-error {{shadows}}
958   };
959 }
960 
961 namespace dr284 { // dr284: no
962   namespace A {
963     struct X;
964     enum Y {};
965     class Z {};
966   }
967   namespace B {
968     struct W;
969     using A::X;
970     using A::Y;
971     using A::Z;
972   }
973   struct B::V {}; // expected-error {{no struct named 'V'}}
974   struct B::W {};
975   struct B::X {}; // FIXME: ill-formed
976   enum B::Y e; // ok per dr417
977   class B::Z z; // ok per dr417
978 
979   struct C {
980     struct X;
981     enum Y {};
982     class Z {};
983   };
984   struct D : C {
985     struct W;
986     using C::X;
987     using C::Y;
988     using C::Z;
989   };
990   struct D::V {}; // expected-error {{no struct named 'V'}}
991   struct D::W {};
992   struct D::X {}; // FIXME: ill-formed
993   enum D::Y e2; // ok per dr417
994   class D::Z z2; // ok per dr417
995 }
996 
997 namespace dr285 { // dr285: yes
998   template<typename T> void f(T, int); // expected-note {{match}}
999   template<typename T> void f(int, T); // expected-note {{match}}
f(int,int)1000   template<> void f<int>(int, int) {} // expected-error {{ambiguous}}
1001 }
1002 
1003 namespace dr286 { // dr286: yes
1004   template<class T> struct A {
1005     class C {
1006       template<class T2> struct B {}; // expected-note {{here}}
1007     };
1008   };
1009 
1010   template<class T>
1011   template<class T2>
1012   struct A<T>::C::B<T2*> { };
1013 
1014   A<short>::C::B<int*> absip; // expected-error {{private}}
1015 }
1016 
1017 // dr288: na
1018 
1019 namespace dr289 { // dr289: yes
1020   struct A; // expected-note {{forward}}
1021   struct B : A {}; // expected-error {{incomplete}}
1022 
1023   template<typename T> struct C { typename T::error error; }; // expected-error {{cannot be used prior to '::'}}
1024   struct D : C<int> {}; // expected-note {{instantiation}}
1025 }
1026 
1027 // dr290: na
1028 // dr291: dup 391
1029 // dr292 FIXME: write a codegen test
1030 
1031 namespace dr294 { // dr294: no
1032   void f() throw(int);
1033 #if __cplusplus > 201402L
1034     // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1035 #endif
main()1036   int main() {
1037     (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before
1038 #if __cplusplus > 201402L
1039     // FIXME: expected-error@-2 {{not allowed}}
1040     //
1041     // Irony: the above is valid in C++17 and beyond, but that's exactly when
1042     // we reject it. In C++14 and before, this is ill-formed because an
1043     // exception-specification is not permitted in a type-id. In C++17, this is
1044     // valid because it's the inverse of a standard conversion sequence
1045     // containing a function pointer conversion. (Well, it's actually not valid
1046     // yet, as a static_cast is not permitted to reverse a function pointer
1047     // conversion, but that is being changed by core issue).
1048 #endif
1049     (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before
1050 #if __cplusplus > 201402L
1051     // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1052 #endif
1053 
1054     void (*p)() throw() = f; // expected-error-re {{{{not superset|different exception specification}}}}
1055     void (*q)() throw(int) = f;
1056 #if __cplusplus > 201402L
1057     // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1058 #endif
1059   }
1060 }
1061 
1062 namespace dr295 { // dr295: 3.7
1063   typedef int f();
1064   const f g; // expected-warning {{'const' qualifier on function type 'dr295::f' (aka 'int ()') has no effect}}
1065   f &r = g;
1066   template<typename T> struct X {
1067     const T &f;
1068   };
1069   X<f> x = {g};
1070 
1071   typedef int U();
1072   typedef const U U; // expected-warning {{'const' qualifier on function type 'dr295::U' (aka 'int ()') has no effect}}
1073 
1074   typedef int (*V)();
1075   typedef volatile U *V; // expected-warning {{'volatile' qualifier on function type 'dr295::U' (aka 'int ()') has no effect}}
1076 }
1077 
1078 namespace dr296 { // dr296: yes
1079   struct A {
operator intdr296::A1080     static operator int() { return 0; } // expected-error {{static}}
1081   };
1082 }
1083 
1084 namespace dr298 { // dr298: yes
1085   struct A {
1086     typedef int type;
1087     A();
1088     ~A();
1089   };
1090   typedef A B; // expected-note {{here}}
1091   typedef const A C; // expected-note {{here}}
1092 
1093   A::type i1;
1094   B::type i2;
1095   C::type i3;
1096 
1097   struct A a;
1098   struct B b; // expected-error {{typedef 'B' cannot be referenced with a struct specifier}}
1099   struct C c; // expected-error {{typedef 'C' cannot be referenced with a struct specifier}}
1100 
B()1101   B::B() {} // expected-error {{requires a type specifier}}
A()1102   B::A() {} // ok
~C()1103   C::~C() {} // expected-error {{destructor cannot be declared using a typedef 'dr298::C' (aka 'const dr298::A') of the class name}}
1104 
1105   typedef struct D E; // expected-note {{here}}
1106   struct E {}; // expected-error {{conflicts with typedef}}
1107 
1108   struct F {
1109     ~F();
1110   };
1111   typedef const F G;
~F()1112   G::~F() {} // ok
1113 }
1114 
1115 namespace dr299 { // dr299: yes c++11
1116   struct S {
1117     operator int();
1118   };
1119   struct T {
1120     operator int(); // expected-note {{}}
1121     operator unsigned short(); // expected-note {{}}
1122   };
1123   // FIXME: should this apply to c++98 mode?
1124   int *p = new int[S()]; // expected-error 0-1{{extension}}
1125   int *q = new int[T()]; // expected-error {{ambiguous}}
1126 }
1127