Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr2xx.cpp
blobc03b7b60bcb4f6f9a13a341e91a24cc4d8cc6546
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 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
8 // PR13819 -- __SIZE_TYPE__ is incompatible.
9 typedef __SIZE_TYPE__ size_t; // expected-error 0-1 {{extension}}
11 #if __cplusplus < 201103L
12 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
13 #else
14 #define fold
15 #endif
17 namespace dr200 { // dr200: dup 214
18 template <class T> T f(int);
19 template <class T, class U> T f(U) = delete; // expected-error 0-1{{extension}}
21 void g() {
22 f<int>(1);
26 // dr201 FIXME: write codegen test
28 namespace dr202 { // dr202: yes
29 template<typename T> T f();
30 template<int (*g)()> struct X {
31 int arr[fold(g == &f<int>) ? 1 : -1];
33 template struct X<f>;
36 // FIXME (export) dr204: no
38 namespace dr206 { // dr206: yes
39 struct S; // expected-note 2{{declaration}}
40 template<typename T> struct Q { S s; }; // expected-error {{incomplete}}
41 template<typename T> void f() { S s; } // expected-error {{incomplete}}
44 namespace dr207 { // dr207: yes
45 class A {
46 protected:
47 static void f() {}
49 class B : A {
50 public:
51 using A::f;
52 void g() {
53 A::f();
54 f();
59 // dr208 FIXME: write codegen test
61 namespace dr209 { // dr209: yes
62 class A {
63 void f(); // expected-note {{here}}
65 class B {
66 friend void A::f(); // expected-error {{private}}
70 // dr210 FIXME: write codegen test
72 namespace dr211 { // dr211: yes
73 struct A {
74 A() try {
75 throw 0;
76 } catch (...) {
77 return; // expected-error {{return in the catch of a function try block of a constructor}}
82 namespace dr213 { // dr213: yes
83 template <class T> struct A : T {
84 void h(T t) {
85 char &r1 = f(t);
86 int &r2 = g(t); // expected-error {{explicit qualification required to use member 'g' from dependent base class}}
89 struct B {
90 int &f(B);
91 int &g(B); // expected-note {{here}}
93 char &f(B);
95 template void A<B>::h(B); // expected-note {{instantiation}}
98 namespace dr214 { // dr214: yes
99 template<typename T, typename U> T checked_cast(U from) { U::error; }
100 template<typename T, typename U> T checked_cast(U *from);
101 class C {};
102 void foo(int *arg) { checked_cast<const C *>(arg); }
104 template<typename T> T f(int);
105 template<typename T, typename U> T f(U) { T::error; }
106 void g() {
107 f<int>(1);
111 namespace dr215 { // dr215: yes
112 template<typename T> class X {
113 friend void T::foo();
114 int n;
116 struct Y {
117 void foo() { (void)+X<Y>().n; }
121 namespace dr216 { // dr216: no
122 // FIXME: Should reject this: 'f' has linkage but its type does not,
123 // and 'f' is odr-used but not defined in this TU.
124 typedef enum { e } *E;
125 void f(E);
126 void g(E e) { f(e); }
128 struct S {
129 // FIXME: Should reject this: 'f' has linkage but its type does not,
130 // and 'f' is odr-used but not defined in this TU.
131 typedef enum { e } *E;
132 void f(E);
134 void g(S s, S::E e) { s.f(e); }
137 namespace dr217 { // dr217: yes
138 template<typename T> struct S {
139 void f(int);
141 template<typename T> void S<T>::f(int = 0) {} // expected-error {{default arguments cannot be added}}
144 namespace dr218 { // dr218: yes
145 // NB: also dup 405
146 namespace A {
147 struct S {};
148 void f(S);
150 namespace B {
151 struct S {};
152 void f(S);
155 struct C {
156 int f;
157 void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}}
158 void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}}
159 void test3(A::S as) { using A::f; f(as); } // ok
160 void test4(A::S as) { using B::f; f(as); } // ok
161 void test5(A::S as) { int f; f(as); } // expected-error {{called object type 'int'}}
162 void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no matching conversion}} expected-note +{{}}
165 namespace D {
166 struct S {};
167 struct X { void operator()(S); } f;
169 void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
171 namespace E {
172 struct S {};
173 struct f { f(S); };
175 void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
177 namespace F {
178 struct S {
179 template<typename T> friend void f(S, T) {}
182 void testF(F::S fs) { f(fs, 0); }
184 namespace G {
185 namespace X {
186 int f;
187 struct A {};
189 namespace Y {
190 template<typename T> void f(T);
191 struct B {};
193 template<typename A, typename B> struct C {};
195 void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }
198 // dr219: na
199 // dr220: na
201 namespace dr221 { // dr221: yes
202 struct A { // expected-note 2-4{{candidate}}
203 A &operator=(int&); // expected-note 2{{candidate}}
204 A &operator+=(int&);
205 static A &operator=(A&, double&); // expected-error {{cannot be a static member}}
206 static A &operator+=(A&, double&); // expected-error {{cannot be a static member}}
207 friend A &operator=(A&, char&); // expected-error {{must be a non-static member function}}
208 friend A &operator+=(A&, char&);
210 A &operator=(A&, float&); // expected-error {{must be a non-static member function}}
211 A &operator+=(A&, float&);
213 void test(A a, int n, char c, float f) {
214 a = n;
215 a += n;
216 a = c; // expected-error {{no viable}}
217 a += c;
218 a = f; // expected-error {{no viable}}
219 a += f;
223 namespace dr222 { // dr222: dup 637
224 void f(int a, int b, int c, int *x) {
225 #pragma clang diagnostic push
226 #pragma clang diagnostic warning "-Wunsequenced"
227 void((a += b) += c);
228 void((a += b) + (a += c)); // expected-warning {{multiple unsequenced modifications to 'a'}}
230 x[a++] = a;
231 #if __cplusplus < 201703L
232 // expected-warning@-2 {{unsequenced modification and access to 'a'}}
233 #endif
235 a = b = 0; // ok, read and write of 'b' are sequenced
237 a = (b = a++);
238 #if __cplusplus < 201703L
239 // expected-warning@-2 {{multiple unsequenced modifications to 'a'}}
240 #endif
241 a = (b = ++a);
242 #pragma clang diagnostic pop
246 // dr223: na
248 namespace dr224 { // dr224: 16
249 namespace example1 {
250 template <class T> class A {
251 typedef int type;
252 A::type a;
253 A<T>::type b;
254 A<T*>::type c;
255 #if __cplusplus <= 201703L
256 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
257 #endif
258 ::dr224::example1::A<T>::type d;
260 class B {
261 typedef int type;
263 A::type a;
264 A<T>::type b;
265 A<T*>::type c;
266 #if __cplusplus <= 201703L
267 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
268 #endif
269 ::dr224::example1::A<T>::type d;
271 B::type e;
272 A<T>::B::type f;
273 A<T*>::B::type g;
274 #if __cplusplus <= 201703L
275 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
276 #endif
277 typename A<T*>::B::type h;
281 template <class T> class A<T*> {
282 typedef int type;
283 A<T*>::type a;
284 A<T>::type b;
285 #if __cplusplus <= 201703L
286 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
287 #endif
290 template <class T1, class T2, int I> struct B {
291 typedef int type;
292 B<T1, T2, I>::type b1;
293 B<T2, T1, I>::type b2;
294 #if __cplusplus <= 201703L
295 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
296 #endif
298 typedef T1 my_T1;
299 static const int my_I = I;
300 static const int my_I2 = I+0;
301 static const int my_I3 = my_I;
302 B<my_T1, T2, my_I>::type b3;
303 B<my_T1, T2, my_I2>::type b4;
304 B<my_T1, T2, my_I3>::type b5;
305 #if __cplusplus <= 201703L
306 // expected-error@-4 {{implicit 'typename' is a C++20 extension}}
307 // expected-error@-4 {{implicit 'typename' is a C++20 extension}}
308 // expected-error@-4 {{implicit 'typename' is a C++20 extension}}
309 #endif
313 namespace example2 {
314 template <int, typename T> struct X { typedef T type; };
315 template <class T> class A {
316 static const int i = 5;
317 X<i, int>::type w;
318 X<A::i, char>::type x;
319 X<A<T>::i, double>::type y;
320 X<A<T*>::i, long>::type z;
321 #if __cplusplus <= 201703L
322 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
323 #endif
324 int f();
326 template <class T> int A<T>::f() {
327 return i;
332 // dr225: yes
333 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}}
334 void dr225_g(int); // expected-note {{should be declared prior to the call site}}
335 template void dr225_f(int); // expected-note {{in instantiation of}}
337 namespace dr226 { // dr226: no
338 template<typename T = void> void f() {}
339 #if __cplusplus < 201103L
340 // expected-error@-2 {{extension}}
341 // FIXME: This appears to be wrong: default arguments for function templates
342 // are listed as a defect (in c++98) not an extension. EDG accepts them in
343 // strict c++98 mode.
344 #endif
345 template<typename T> struct S {
346 template<typename U = void> void g();
347 #if __cplusplus < 201103L
348 // expected-error@-2 {{extension}}
349 #endif
350 template<typename U> struct X;
351 template<typename U> void h();
353 template<typename T> template<typename U> void S<T>::g() {}
354 template<typename T> template<typename U = void> struct S<T>::X {}; // expected-error {{cannot add a default template arg}}
355 template<typename T> template<typename U = void> void S<T>::h() {} // expected-error {{cannot add a default template arg}}
357 template<typename> void friend_h();
358 struct A {
359 // FIXME: This is ill-formed.
360 template<typename=void> struct friend_B;
361 // FIXME: f, h, and i are ill-formed.
362 // f is ill-formed because it is not a definition.
363 // h and i are ill-formed because they are not the only declarations of the
364 // function in the translation unit.
365 template<typename=void> void friend_f();
366 template<typename=void> void friend_g() {}
367 template<typename=void> void friend_h() {}
368 template<typename=void> void friend_i() {}
369 #if __cplusplus < 201103L
370 // expected-error@-5 {{extension}} expected-error@-4 {{extension}}
371 // expected-error@-4 {{extension}} expected-error@-3 {{extension}}
372 #endif
374 template<typename> void friend_i();
376 template<typename=void, typename X> void foo(X) {}
377 template<typename=void, typename X> struct Foo {}; // expected-error {{missing a default argument}} expected-note {{here}}
378 #if __cplusplus < 201103L
379 // expected-error@-3 {{extension}}
380 #endif
382 template<typename=void, typename X, typename, typename Y> int foo(X, Y);
383 template<typename, typename X, typename=void, typename Y> int foo(X, Y);
384 int x = foo(0, 0);
385 #if __cplusplus < 201103L
386 // expected-error@-4 {{extension}}
387 // expected-error@-4 {{extension}}
388 #endif
391 void dr227(bool b) { // dr227: yes
392 if (b)
393 int n;
394 else
395 int n;
398 namespace dr228 { // dr228: yes
399 template <class T> struct X {
400 void f();
402 template <class T> struct Y {
403 void g(X<T> x) { x.template X<T>::f(); }
407 namespace dr229 { // dr229: yes
408 template<typename T> void f();
409 template<typename T> void f<T*>() {} // expected-error {{function template partial specialization}}
410 template<> void f<int>() {}
413 namespace dr230 { // dr230: yes
414 struct S {
415 S() { f(); } // expected-warning {{call to pure virtual member function}}
416 virtual void f() = 0; // expected-note {{declared here}}
420 namespace dr231 { // dr231: yes
421 namespace outer {
422 namespace inner {
423 int i; // expected-note {{here}}
425 void f() { using namespace inner; }
426 int j = i; // expected-error {{undeclared identifier 'i'; did you mean 'inner::i'?}}
430 // dr234: na
431 // dr235: na
433 namespace dr236 { // dr236: yes
434 void *p = int();
435 #if __cplusplus < 201103L
436 // expected-warning@-2 {{null pointer}}
437 #else
438 // expected-error@-4 {{cannot initialize}}
439 #endif
442 namespace dr237 { // dr237: dup 470
443 template<typename T> struct A { void f() { T::error; } };
444 template<typename T> struct B : A<T> {};
445 template struct B<int>; // ok
448 namespace dr239 { // dr239: yes
449 namespace NS {
450 class T {};
451 void f(T);
452 float &g(T, int);
454 NS::T parm;
455 int &g(NS::T, float);
456 int main() {
457 f(parm);
458 float &r = g(parm, 1);
459 extern int &g(NS::T, float);
460 int &s = g(parm, 1);
464 // dr240: dup 616
466 namespace dr241 { // dr241: yes
467 namespace A {
468 struct B {};
469 template <int X> void f(); // expected-note 3{{candidate}}
470 template <int X> void g(B);
472 namespace C {
473 template <class T> void f(T t); // expected-note 2{{candidate}}
474 template <class T> void g(T t); // expected-note {{candidate}}
476 void h(A::B b) {
477 f<3>(b); // expected-error 0-1{{C++20 extension}} expected-error {{no matching}}
478 g<3>(b); // expected-error 0-1{{C++20 extension}}
479 A::f<3>(b); // expected-error {{no matching}}
480 A::g<3>(b);
481 C::f<3>(b); // expected-error {{no matching}}
482 C::g<3>(b); // expected-error {{no matching}}
483 using C::f;
484 using C::g;
485 f<3>(b); // expected-error {{no matching}}
486 g<3>(b);
490 namespace dr243 { // dr243: yes
491 struct B;
492 struct A {
493 A(B); // expected-note {{candidate}}
495 struct B {
496 operator A() = delete; // expected-error 0-1{{extension}} expected-note {{candidate}}
497 } b;
498 A a1(b);
499 A a2 = b; // expected-error {{ambiguous}}
502 namespace dr244 { // dr244: 11
503 // NB: this test is reused by dr399
504 struct B {}; // expected-note {{type 'dr244::B' found by destructor name lookup}}
505 struct D : B {};
507 D D_object;
508 typedef B B_alias;
509 B* B_ptr = &D_object;
511 void f() {
512 D_object.~B(); // expected-error {{does not match the type 'D' of the object being destroyed}}
513 D_object.B::~B();
514 D_object.D::~B(); // FIXME: Missing diagnostic for this.
515 B_ptr->~B();
516 B_ptr->~B_alias();
517 B_ptr->B_alias::~B();
518 B_ptr->B_alias::~B_alias();
519 B_ptr->dr244::~B(); // expected-error {{refers to a member in namespace}}
520 B_ptr->dr244::~B_alias(); // expected-error {{refers to a member in namespace}}
523 template<typename T, typename U>
524 void f(T *B_ptr, U D_object) {
525 D_object.~B(); // FIXME: Missing diagnostic for this.
526 D_object.B::~B();
527 D_object.D::~B(); // FIXME: Missing diagnostic for this.
528 B_ptr->~B();
529 B_ptr->~B_alias();
530 B_ptr->B_alias::~B();
531 B_ptr->B_alias::~B_alias();
532 B_ptr->dr244::~B(); // expected-error {{does not refer to a type name}}
533 B_ptr->dr244::~B_alias(); // expected-error {{does not refer to a type name}}
535 template void f<B, D>(B*, D);
537 namespace N {
538 template<typename T> struct E {};
539 typedef E<int> F;
541 void g(N::F f) {
542 typedef N::F G; // expected-note {{found by destructor name lookup}}
543 f.~G();
544 f.G::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
545 f.G::~F(); // expected-error {{undeclared identifier 'F' in destructor name}}
546 f.G::~G();
547 // This is technically ill-formed; E is looked up in 'N::' and names the
548 // class template, not the injected-class-name of the class. But that's
549 // probably a bug in the standard.
550 f.N::F::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
551 // This is valid; we look up the second F in the same scope in which we
552 // found the first one, that is, 'N::'.
553 f.N::F::~F();
554 // This is technically ill-formed; G is looked up in 'N::' and is not found.
555 // Rejecting this seems correct, but most compilers accept, so we do also.
556 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}}
559 // Bizarrely, compilers perform lookup in the scope for qualified destructor
560 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
561 // this.
562 namespace QualifiedLookupInScope {
563 namespace N {
564 template <typename> struct S { struct Inner {}; };
566 template <typename U> void f(typename N::S<U>::Inner *p) {
567 typedef typename N::S<U>::Inner T;
568 p->::dr244::QualifiedLookupInScope::N::S<U>::Inner::~T(); // expected-error {{no type named 'T' in}}
570 template void f<int>(N::S<int>::Inner *); // expected-note {{instantiation of}}
572 template <typename U> void g(U *p) {
573 typedef U T;
574 p->T::~T();
575 p->U::~T();
576 p->::dr244::QualifiedLookupInScope::N::S<int>::Inner::~T(); // expected-error {{'T' does not refer to a type name}}
578 template void g(N::S<int>::Inner *);
582 namespace dr245 { // dr245: yes
583 struct S {
584 enum E {}; // expected-note {{here}}
585 class E *p; // expected-error {{does not match previous declaration}}
589 namespace dr246 { // dr246: yes
590 struct S {
591 S() try { // expected-note {{try block}}
592 throw 0;
593 X: ;
594 } catch (int) {
595 goto X; // expected-error {{cannot jump}}
600 namespace dr247 { // dr247: yes
601 struct A {};
602 struct B : A {
603 void f();
604 void f(int);
606 void (A::*f)() = (void (A::*)())&B::f;
608 struct C {
609 void f();
610 void f(int);
612 struct D : C {};
613 void (C::*g)() = &D::f;
614 void (D::*h)() = &D::f;
616 struct E {
617 void f();
619 struct F : E {
620 using E::f;
621 void f(int);
623 void (F::*i)() = &F::f;
626 namespace dr248 { // dr248: sup P1949
627 int \u040d\u040e = 0;
630 namespace dr249 { // dr249: yes
631 template<typename T> struct X { void f(); };
632 template<typename T> void X<T>::f() {}
635 namespace dr250 { // dr250: yes
636 typedef void (*FPtr)(double x[]);
638 template<int I> void f(double x[]);
639 FPtr fp = &f<3>;
641 template<int I = 3> void g(double x[]); // expected-error 0-1{{extension}}
642 FPtr gp = &g<>;
645 namespace dr252 { // dr252: yes
646 struct A {
647 void operator delete(void*); // expected-note {{found}}
649 struct B {
650 void operator delete(void*); // expected-note {{found}}
652 struct C : A, B {
653 virtual ~C();
655 C::~C() {} // expected-error {{'operator delete' found in multiple base classes}}
657 struct D {
658 void operator delete(void*, int); // expected-note {{here}}
659 virtual ~D();
661 D::~D() {} // expected-error {{no suitable member 'operator delete'}}
663 struct E {
664 void operator delete(void*, int);
665 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note 1-2 {{here}}
666 virtual ~E(); // expected-error 0-1 {{attempt to use a deleted function}}
668 E::~E() {} // expected-error {{attempt to use a deleted function}}
670 struct F {
671 // If both functions are available, the first one is a placement delete.
672 void operator delete(void*, size_t);
673 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note {{here}}
674 virtual ~F();
676 F::~F() {} // expected-error {{attempt to use a deleted function}}
678 struct G {
679 void operator delete(void*, size_t);
680 virtual ~G();
682 G::~G() {}
685 namespace dr254 { // dr254: yes
686 template<typename T> struct A {
687 typedef typename T::type type; // ok even if this is a typedef-name, because
688 // it's not an elaborated-type-specifier
689 typedef struct T::type foo; // expected-error {{typedef 'type' cannot be referenced with a struct specifier}}
691 struct B { struct type {}; };
692 struct C { typedef struct {} type; }; // expected-note {{here}}
693 A<B>::type n;
694 A<C>::type n; // expected-note {{instantiation of}}
697 namespace dr255 { // dr255: yes
698 struct S {
699 void operator delete(void *){};
700 void operator delete(void *, int){};
702 void f(S *p) { delete p; }
703 } // namespace dr255
705 // dr256: dup 624
707 namespace dr257 { // dr257: yes
708 struct A { A(int); }; // expected-note {{here}}
709 struct B : virtual A {
710 B() {}
711 virtual void f() = 0;
713 struct C : B {
714 C() {}
716 struct D : B {
717 D() {} // expected-error {{must explicitly initialize the base class 'A'}}
718 void f();
722 namespace dr258 { // dr258: yes
723 struct A {
724 void f(const int);
725 template<typename> void g(int);
726 float &h() const;
728 struct B : A {
729 using A::f;
730 using A::g;
731 using A::h;
732 int &f(int);
733 template<int> int &g(int); // expected-note {{candidate}}
734 int &h();
735 } b;
736 int &w = b.f(0);
737 int &x = b.g<int>(0); // expected-error {{no match}}
738 int &y = b.h();
739 float &z = const_cast<const B&>(b).h();
741 struct C {
742 virtual void f(const int) = 0;
744 struct D : C {
745 void f(int);
746 } d;
748 struct E {
749 virtual void f() = 0; // expected-note {{unimplemented}}
751 struct F : E {
752 void f() const {}
753 } f; // expected-error {{abstract}}
756 namespace dr259 { // dr259: 4
757 template<typename T> struct A {};
758 template struct A<int>; // expected-note {{previous}}
759 template struct A<int>; // expected-error {{duplicate explicit instantiation}}
761 template<> struct A<float>; // expected-note {{previous}}
762 template struct A<float>; // expected-warning {{has no effect}}
764 template struct A<char>; // expected-note {{here}}
765 template<> struct A<char>; // expected-error {{explicit specialization of 'dr259::A<char>' after instantiation}}
767 template<> struct A<double>;
768 template<> struct A<double>;
769 template<> struct A<double> {}; // expected-note {{here}}
770 template<> struct A<double> {}; // expected-error {{redefinition}}
772 template<typename T> struct B; // expected-note {{here}}
773 template struct B<int>; // expected-error {{undefined}}
775 template<> struct B<float>; // expected-note {{previous}}
776 template struct B<float>; // expected-warning {{has no effect}}
779 // FIXME: When dr260 is resolved, also add tests for DR507.
781 namespace dr261 { // dr261: no
782 #pragma clang diagnostic push
783 #pragma clang diagnostic warning "-Wused-but-marked-unused"
785 // FIXME: This is ill-formed, with a diagnostic required, because operator new
786 // and operator delete are inline and odr-used, but not defined in this
787 // translation unit.
788 // We're also missing the -Wused-but-marked-unused diagnostic here.
789 struct A {
790 inline void *operator new(size_t) __attribute__((unused));
791 inline void operator delete(void*) __attribute__((unused));
792 A() {}
795 // FIXME: This is ill-formed, with a required diagnostic, for the same
796 // reason.
797 struct B {
798 inline void operator delete(void*) __attribute__((unused));
799 ~B() {}
801 struct C {
802 inline void operator delete(void*) __attribute__((unused));
803 virtual ~C() {} // expected-warning {{'operator delete' was marked unused but was used}}
806 struct D {
807 inline void operator delete(void*) __attribute__((unused));
809 void h() { C::operator delete(0); } // expected-warning {{marked unused but was used}}
811 #pragma clang diagnostic pop
814 namespace dr262 { // dr262: yes
815 int f(int = 0, ...);
816 int k = f();
817 int l = f(0);
818 int m = f(0, 0);
821 namespace dr263 { // dr263: yes
822 struct X {};
823 struct Y {
824 #if __cplusplus < 201103L
825 friend X::X() throw();
826 friend X::~X() throw();
827 #elif __cplusplus <= 201703L
828 friend constexpr X::X() noexcept;
829 friend X::~X();
830 #else
831 friend constexpr X::X() noexcept;
832 friend constexpr X::~X();
833 #endif
834 Y::Y(); // expected-error {{extra qualification}}
835 Y::~Y(); // expected-error {{extra qualification}}
839 // dr265: dup 353
840 // dr266: na
841 // dr269: na
842 // dr270: na
844 namespace dr272 { // dr272: yes
845 struct X {
846 void f() {
847 this->~X();
848 X::~X();
849 ~X(); // expected-error {{unary expression}}
854 #include <stdarg.h>
855 #include <stddef.h>
856 namespace dr273 { // dr273: yes
857 struct A {
858 int n;
860 void operator&(A);
861 void f(A a, ...) {
862 offsetof(A, n);
863 va_list val;
864 va_start(val, a);
865 va_end(val);
869 // dr274: na
871 namespace dr275 { // dr275: no
872 namespace N {
873 template <class T> void f(T) {} // expected-note 1-4{{here}}
874 template <class T> void g(T) {} // expected-note {{candidate}}
875 template <> void f(int);
876 template <> void f(char);
877 template <> void f(double);
878 template <> void g(char);
881 using namespace N;
883 namespace M {
884 template <> void N::f(char) {} // expected-error {{'M' does not enclose namespace 'N'}}
885 template <class T> void g(T) {}
886 template <> void g(char) {}
887 template void f(long);
888 #if __cplusplus >= 201103L
889 // FIXME: this should be rejected in c++98 too
890 // expected-error@-3 {{must occur in namespace 'N'}}
891 #endif
892 template void N::f(unsigned long);
893 #if __cplusplus >= 201103L
894 // FIXME: this should be rejected in c++98 too
895 // expected-error@-3 {{not in a namespace enclosing 'N'}}
896 #endif
897 template void h(long); // expected-error {{does not refer to a function template}}
898 template <> void f(double) {} // expected-error {{no function template matches}}
901 template <class T> void g(T) {} // expected-note {{candidate}}
903 template <> void N::f(char) {}
904 template <> void f(int) {} // expected-error {{no function template matches}}
906 template void f(short);
907 #if __cplusplus >= 201103L
908 // FIXME: this should be rejected in c++98 too
909 // expected-error@-3 {{must occur in namespace 'N'}}
910 #endif
911 template void N::f(unsigned short);
913 // FIXME: this should probably be valid. the wording from the issue
914 // doesn't clarify this, but it follows from the usual rules.
915 template void g(int); // expected-error {{ambiguous}}
917 // FIXME: likewise, this should also be valid.
918 template<typename T> void f(T) {} // expected-note {{candidate}}
919 template void f(short); // expected-error {{ambiguous}}
922 // dr276: na
924 namespace dr277 { // dr277: yes
925 typedef int *intp;
926 int *p = intp();
927 int a[fold(intp() ? -1 : 1)];
930 namespace dr280 { // dr280: yes
931 typedef void f0();
932 typedef void f1(int);
933 typedef void f2(int, int);
934 typedef void f3(int, int, int);
935 struct A {
936 operator f1*(); // expected-note {{here}} expected-note {{candidate}}
937 operator f2*();
939 struct B {
940 operator f0*(); // expected-note {{candidate}}
941 private:
942 operator f3*(); // expected-note {{here}} expected-note {{candidate}}
944 struct C {
945 operator f0*(); // expected-note {{candidate}}
946 operator f1*(); // expected-note {{candidate}}
947 operator f2*(); // expected-note {{candidate}}
948 operator f3*(); // expected-note {{candidate}}
950 struct D : private A, B { // expected-note {{here}}
951 operator f2*(); // expected-note {{candidate}}
952 } d;
953 struct E : C, D {} e;
954 void g() {
955 d(); // ok, public
956 d(0); // expected-error {{private member of 'dr280::A'}}
957 d(0, 0); // ok, suppressed by member in D
958 d(0, 0, 0); // expected-error {{private member of 'dr280::B'}}
959 e(); // expected-error {{ambiguous}}
960 e(0); // expected-error {{ambiguous}}
961 e(0, 0); // expected-error {{ambiguous}}
962 e(0, 0, 0); // expected-error {{ambiguous}}
966 namespace dr281 { // dr281: no
967 void a();
968 inline void b();
970 void d();
971 inline void e();
973 struct S {
974 friend inline void a(); // FIXME: ill-formed
975 friend inline void b();
976 friend inline void c(); // FIXME: ill-formed
977 friend inline void d() {}
978 friend inline void e() {}
979 friend inline void f() {}
983 namespace dr283 { // dr283: yes
984 template<typename T> // expected-note 2{{here}}
985 struct S {
986 friend class T; // expected-error {{shadows}}
987 class T; // expected-error {{shadows}}
991 namespace dr284 { // dr284: no
992 namespace A {
993 struct X;
994 enum Y {};
995 class Z {};
997 namespace B {
998 struct W;
999 using A::X;
1000 using A::Y;
1001 using A::Z;
1003 struct B::V {}; // expected-error {{no struct named 'V'}}
1004 struct B::W {};
1005 struct B::X {}; // FIXME: ill-formed
1006 enum B::Y e; // ok per dr417
1007 class B::Z z; // ok per dr417
1009 struct C {
1010 struct X;
1011 enum Y {};
1012 class Z {};
1014 struct D : C {
1015 struct W;
1016 using C::X;
1017 using C::Y;
1018 using C::Z;
1020 struct D::V {}; // expected-error {{no struct named 'V'}}
1021 struct D::W {};
1022 struct D::X {}; // FIXME: ill-formed
1023 enum D::Y e2; // ok per dr417
1024 class D::Z z2; // ok per dr417
1027 namespace dr285 { // dr285: yes
1028 template<typename T> void f(T, int); // expected-note {{match}}
1029 template<typename T> void f(int, T); // expected-note {{match}}
1030 template<> void f<int>(int, int) {} // expected-error {{ambiguous}}
1033 namespace dr286 { // dr286: yes
1034 template<class T> struct A {
1035 class C {
1036 template<class T2> struct B {}; // expected-note {{here}}
1040 template<class T>
1041 template<class T2>
1042 struct A<T>::C::B<T2*> { };
1044 A<short>::C::B<int*> absip; // expected-error {{private}}
1047 // dr288: na
1049 namespace dr289 { // dr289: yes
1050 struct A; // expected-note {{forward}}
1051 struct B : A {}; // expected-error {{incomplete}}
1053 template<typename T> struct C { typename T::error error; }; // expected-error {{cannot be used prior to '::'}}
1054 struct D : C<int> {}; // expected-note {{instantiation}}
1057 // dr290: na
1058 // dr291: dup 391
1059 // dr292 FIXME: write a codegen test
1061 namespace dr294 { // dr294: no
1062 void f() throw(int);
1063 #if __cplusplus > 201402L
1064 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1065 #endif
1066 int main() {
1067 (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before
1068 #if __cplusplus > 201402L
1069 // FIXME: expected-error@-2 {{not allowed}}
1071 // Irony: the above is valid in C++17 and beyond, but that's exactly when
1072 // we reject it. In C++14 and before, this is ill-formed because an
1073 // exception-specification is not permitted in a type-id. In C++17, this is
1074 // valid because it's the inverse of a standard conversion sequence
1075 // containing a function pointer conversion. (Well, it's actually not valid
1076 // yet, as a static_cast is not permitted to reverse a function pointer
1077 // conversion, but that is being changed by core issue).
1078 #endif
1079 (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before
1080 #if __cplusplus > 201402L
1081 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1082 #endif
1084 void (*p)() throw() = f; // expected-error-re {{{{not superset|different exception specification}}}}
1085 void (*q)() throw(int) = f;
1086 #if __cplusplus > 201402L
1087 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1088 #endif
1092 namespace dr295 { // dr295: 3.7
1093 typedef int f();
1094 const f g; // expected-warning {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}}
1095 f &r = g;
1096 template<typename T> struct X {
1097 const T &f;
1099 X<f> x = {g};
1101 typedef int U();
1102 typedef const U U; // expected-warning {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}}
1104 typedef int (*V)();
1105 typedef volatile U *V; // expected-warning {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}}
1108 namespace dr296 { // dr296: yes
1109 struct A {
1110 static operator int() { return 0; } // expected-error {{static}}
1114 namespace dr298 { // dr298: yes
1115 struct A {
1116 typedef int type;
1117 A();
1118 ~A();
1120 typedef A B; // expected-note {{here}}
1121 typedef const A C; // expected-note {{here}}
1123 A::type i1;
1124 B::type i2;
1125 C::type i3;
1127 struct A a;
1128 struct B b; // expected-error {{typedef 'B' cannot be referenced with a struct specifier}}
1129 struct C c; // expected-error {{typedef 'C' cannot be referenced with a struct specifier}}
1131 B::B() {} // expected-error {{a type specifier is required}}
1132 B::A() {} // ok
1133 C::~C() {} // expected-error {{destructor cannot be declared using a typedef 'C' (aka 'const dr298::A') of the class name}}
1135 typedef struct D E; // expected-note {{here}}
1136 struct E {}; // expected-error {{conflicts with typedef}}
1138 struct F {
1139 ~F();
1141 typedef const F G;
1142 G::~F() {} // ok
1145 namespace dr299 { // dr299: yes c++11
1146 struct S {
1147 operator int();
1149 struct T {
1150 operator int(); // expected-note {{}}
1151 operator unsigned short(); // expected-note {{}}
1153 // FIXME: should this apply to c++98 mode?
1154 int *p = new int[S()]; // expected-error 0-1{{extension}}
1155 int *q = new int[T()]; // expected-error {{ambiguous}}