Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr4xx.cpp
blobd8bdf49d0b2dde730fc261cadfe4ff36d2eb29a8
1 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
8 // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
9 __extension__ typedef __SIZE_TYPE__ size_t;
11 namespace std { struct type_info; }
13 namespace dr400 { // dr400: yes
14 struct A { int a; struct a {}; }; // expected-note 2{{conflicting}} expected-note {{ambiguous}}
15 struct B { int a; struct a {}; }; // expected-note 2{{target}} expected-note {{ambiguous}}
16 struct C : A, B { using A::a; struct a b; };
17 struct D : A, B { using A::a; using B::a; struct a b; }; // expected-error 2{{conflicts}}
18 struct E : A, B { struct a b; }; // expected-error {{found in multiple base classes}}
21 namespace dr401 { // dr401: yes
22 template<class T, class U = typename T::type> class A : public T {}; // expected-error {{protected}} expected-error 2{{private}}
24 class B {
25 protected:
26 typedef int type; // expected-note {{protected}}
27 #if __cplusplus == 199711L
28 // expected-note@-2 {{protected}}
29 #endif
32 class C {
33 typedef int type; // expected-note {{private}}
34 friend class A<C>; // expected-note {{default argument}}
37 class D {
38 typedef int type; // expected-note {{private}}
39 friend class A<D, int>;
42 A<B> *b; // expected-note {{default argument}}
43 A<D> *d; // expected-note {{in instantiation of default argument}}
45 struct E {
46 template<class T, class U = typename T::type> class A : public T {};
48 class F {
49 typedef int type;
50 friend class E;
52 E::A<F> eaf; // ok, default argument is in befriended context
54 // FIXME: Why do we get different diagnostics in C++11 onwards here? We seem
55 // to not treat the default template argument as a SFINAE context in C++98.
56 template<class T, class U = typename T::type> void f(T) {}
57 void g(B b) { f(b); }
58 #if __cplusplus < 201103L
59 // expected-error@-3 0-1{{extension}} expected-error@-3 {{protected}} expected-note@-3 {{instantiation}}
60 // expected-note@-3 {{substituting}}
61 #else
62 // expected-error@-5 {{no matching}} expected-note@-6 {{protected}}
63 #endif
66 namespace dr403 { // dr403: yes
67 namespace A {
68 struct S {};
69 int f(void*);
71 template<typename T> struct X {};
72 typedef struct X<A::S>::X XS;
73 XS *p;
74 int k = f(p); // ok, finds A::f, even though type XS is a typedef-name
75 // referring to an elaborated-type-specifier naming a
76 // injected-class-name, which is about as far from a
77 // template-id as we can make it.
80 // dr404: na
81 // (NB: also sup 594)
83 namespace dr405 { // dr405: yes
84 // NB: also dup 218
85 namespace A {
86 struct S {};
87 void f(S);
89 namespace B {
90 struct S {};
91 void f(S);
94 struct C {
95 int f;
96 void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}}
97 void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}}
98 void test3(A::S as) { using A::f; f(as); } // ok
99 void test4(A::S as) { using B::f; f(as); } // ok
100 void test5(A::S as) { int f; f(as); } // expected-error {{called object type 'int'}}
101 void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no matching conversion}} expected-note +{{}}
104 namespace D {
105 struct S {};
106 struct X { void operator()(S); } f;
108 void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
110 namespace E {
111 struct S {};
112 struct f { f(S); };
114 void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
117 namespace dr406 { // dr406: yes
118 typedef struct {
119 static int n; // expected-error {{static data member 'n' not allowed in anonymous struct}}
120 } A;
121 typedef union {
122 static int n; // expected-error {{static data member 'n' not allowed in anonymous union}}
123 } B;
126 namespace dr407 { // dr407: 3.8
127 // NB: reused by dr1894 and dr2199
128 struct S;
129 typedef struct S S;
130 void f() {
131 struct S *p;
133 typedef struct S S; // expected-note {{here}}
134 struct S *p; // expected-error {{typedef 'S' cannot be referenced with a struct specifier}}
137 struct S {};
139 namespace UsingDir {
140 namespace A {
141 struct S {}; // expected-note {{found}}
143 namespace B {
144 typedef int S; // expected-note {{found}}
146 namespace C {
147 using namespace A;
148 using namespace B;
149 struct S s; // expected-error {{ambiguous}}
151 namespace D {
152 using A::S;
153 typedef struct S S;
154 struct S s;
156 namespace E {
157 // The standard doesn't say whether this is valid. We interpret
158 // DR407 as meaning "if lookup finds both a tag and a typedef with the
159 // same type, then it's OK in an elaborated-type-specifier".
160 typedef A::S S;
161 using A::S;
162 struct S s;
164 namespace F {
165 typedef A::S S;
167 // The standard doesn't say what to do in these cases either.
168 namespace G {
169 using namespace A;
170 using namespace F;
171 struct S s;
173 namespace H {
174 using namespace F;
175 using namespace A;
176 struct S s;
181 namespace dr408 { // dr408: 3.4
182 template<int N> void g() { int arr[N != 1 ? 1 : -1]; }
183 template<> void g<2>() { }
185 template<typename T> struct S {
186 static int i[];
187 void f();
189 template<typename T> int S<T>::i[] = { 1 };
191 template<typename T> void S<T>::f() {
192 g<sizeof (i) / sizeof (int)>();
194 template<> int S<int>::i[] = { 1, 2 };
195 template void S<int>::f(); // uses g<2>(), not g<1>().
198 template<typename T> struct R {
199 static int arr[];
200 void f();
202 template<typename T> int R<T>::arr[1];
203 template<typename T> void R<T>::f() {
204 int arr[sizeof(arr) != sizeof(int) ? 1 : -1];
206 template<> int R<int>::arr[2];
207 template void R<int>::f();
210 namespace dr409 { // dr409: yes
211 template<typename T> struct A {
212 typedef int B;
213 B b1;
214 A::B b2;
215 A<T>::B b3;
216 A<T*>::B b4;
217 #if __cplusplus <= 201703L
218 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
219 #endif
223 namespace dr410 { // dr410: no
224 template<class T> void f(T);
225 void g(int);
226 namespace M {
227 template<class T> void h(T);
228 template<class T> void i(T);
229 struct A {
230 friend void f<>(int);
231 friend void h<>(int);
232 friend void g(int);
233 template<class T> void i(T);
234 friend void i<>(int);
235 private:
236 static void z(); // expected-note {{private}}
239 template<> void h(int) { A::z(); }
240 // FIXME: This should be ill-formed. The member A::i<> is befriended,
241 // not this function.
242 template<> void i(int) { A::z(); }
244 template<> void f(int) { M::A::z(); }
245 void g(int) { M::A::z(); } // expected-error {{private}}
248 // dr412 is in its own file.
250 namespace dr413 { // dr413: yes
251 struct S {
252 int a;
253 int : 17;
254 int b;
256 S s = { 1, 2, 3 }; // expected-error {{excess elements}}
258 struct E {};
259 struct T { // expected-note {{here}}
260 int a;
261 E e;
262 int b;
264 T t1 = { 1, {}, 2 };
265 T t2 = { 1, 2 }; // expected-error {{aggregate with no elements requires explicit braces}}
268 namespace dr414 { // dr414: dup 305
269 struct X {};
270 void f() {
271 X x;
272 struct X {};
273 x.~X();
277 namespace dr415 { // dr415: yes
278 template<typename T> void f(T, ...) { T::error; }
279 void f(int, int);
280 void g() { f(0, 0); } // ok
283 namespace dr416 { // dr416: yes
284 extern struct A a;
285 int &operator+(const A&, const A&);
286 int &k = a + a;
287 struct A { float &operator+(A&); };
288 float &f = a + a;
291 namespace dr417 { // dr417: no
292 struct A;
293 struct dr417::A {}; // expected-warning {{extra qualification}}
294 struct B { struct X; };
295 struct C : B {};
296 struct C::X {}; // expected-error {{no struct named 'X' in 'dr417::C'}}
297 struct B::X { struct Y; };
298 struct C::X::Y {}; // ok!
299 namespace N {
300 struct D;
301 struct E;
302 struct F;
303 struct H;
305 // FIXME: This is ill-formed.
306 using N::D;
307 struct dr417::D {}; // expected-warning {{extra qualification}}
308 using namespace N;
309 struct dr417::E {}; // expected-warning {{extra qualification}} expected-error {{no struct named 'E'}}
310 struct N::F {};
311 struct G;
312 using N::H;
313 namespace M {
314 struct dr417::G {}; // expected-error {{namespace 'M' does not enclose}}
315 struct dr417::H {}; // expected-error {{namespace 'M' does not enclose}}
319 namespace dr418 { // dr418: no
320 namespace example1 {
321 void f1(int, int = 0);
322 void f1(int = 0, int);
324 void g() { f1(); }
325 } // namespace example1
327 namespace example2 {
328 namespace A {
329 void f2(int); // #dr418-f2-decl
331 namespace B {
332 using A::f2;
334 namespace A {
335 void f2(int = 3);
337 void g2() {
338 using B::f2;
339 f2(); // expected-error {{no matching function}}
340 // expected-note@#dr418-f2-decl {{requires 1 argument}}
342 } // namespace example2
344 // example from [over.match.best]/4
345 namespace example3 {
346 namespace A {
347 extern "C" void f(int = 5);
349 namespace B {
350 extern "C" void f(int = 5);
353 using A::f;
354 using B::f;
356 void use() {
357 f(3);
358 f(); // FIXME: this should fail
360 } // namespace example3
361 } // namespace dr418
363 namespace dr420 { // dr420: yes
364 template<typename T> struct ptr {
365 T *operator->() const;
366 T &operator*() const;
368 template<typename T, typename P> void test(P p) {
369 p->~T();
370 p->T::~T();
371 (*p).~T();
372 (*p).T::~T();
374 struct X {};
375 template void test<int>(int*);
376 template void test<int>(ptr<int>);
377 template void test<X>(X*);
378 template void test<X>(ptr<X>);
380 template<typename T>
381 void test2(T p) {
382 p->template Y<int>::~Y<int>();
383 p->~Y<int>();
384 p->template ~Y<int>(); // expected-error {{'template' keyword not permitted in destructor name}}
386 template<typename T> struct Y {};
387 template void test2(Y<int>*);
388 template void test2(ptr<Y<int> >);
390 void test3(int *p, ptr<int> q) {
391 typedef int Int;
392 p->~Int();
393 q->~Int();
394 p->Int::~Int();
395 q->Int::~Int();
398 #if __cplusplus >= 201103L
399 template<typename T> using id = T;
400 struct A { template<typename T> using id = T; };
401 void test4(int *p, ptr<int> q) {
402 p->~id<int>();
403 q->~id<int>();
404 p->id<int>::~id<int>();
405 q->id<int>::~id<int>();
406 p->template id<int>::~id<int>(); // OK since dr2292
407 q->template id<int>::~id<int>(); // OK since dr2292
408 p->A::template id<int>::~id<int>();
409 q->A::template id<int>::~id<int>();
411 #endif
414 namespace dr421 { // dr421: yes
415 struct X { X(); int n; int &r; };
416 int *p = &X().n; // expected-error-re {{{{taking the address of a temporary|cannot take the address of an rvalue}}}}
417 int *q = &X().r;
420 namespace dr422 { // dr422: yes
421 template<typename T, typename U> void f() {
422 typedef T type; // expected-note {{prev}}
423 typedef U type; // expected-error {{redef}}
425 template void f<int, int>();
426 template void f<int, char>(); // expected-note {{instantiation}}
429 namespace dr423 { // dr423: yes
430 template<typename T> struct X { operator T&(); };
431 void f(X<int> x) { x += 1; }
434 namespace dr424 { // dr424: yes
435 struct A {
436 typedef int N; // expected-note {{previous}}
437 typedef int N; // expected-error {{redefinition}}
439 struct X;
440 typedef X X; // expected-note {{previous}}
441 struct X {};
443 struct X *p;
444 struct A::X *q;
445 X *r;
447 typedef X X; // expected-error {{redefinition}}
449 struct B {
450 typedef int N;
452 struct C : B {
453 typedef int N; // expected-note {{previous}}
454 typedef int N; // expected-error {{redefinition}}
458 namespace dr425 { // dr425: yes
459 struct A { template<typename T> operator T() const; } a;
460 float f = 1.0f * a; // expected-error {{ambiguous}} expected-note 5+{{built-in candidate}}
462 template<typename T> struct is_float;
463 template<> struct is_float<float> { typedef void type; };
465 struct B {
466 template<typename T, typename U = typename is_float<T>::type> operator T() const; // expected-error 0-1{{extension}}
467 } b;
468 float g = 1.0f * b; // ok
471 namespace dr427 { // dr427: yes
472 struct B {};
473 struct D : public B {
474 D(B &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
477 extern D d1;
478 B &b = d1;
479 const D &d2 = static_cast<const D&>(b);
480 const D &d3 = (const D&)b;
481 const D &d4(b); // expected-error {{deleted}}
484 namespace dr428 { // dr428: yes
485 template<typename T> T make();
486 extern struct X x; // expected-note 5{{forward declaration}}
487 void f() {
488 throw void(); // expected-error {{cannot throw}}
489 throw make<void*>();
490 throw make<const volatile void*>();
491 throw x; // expected-error {{cannot throw}}
492 throw make<X&>(); // expected-error {{cannot throw}}
493 throw make<X*>(); // expected-error {{cannot throw}}
494 throw make<const volatile X&>(); // expected-error {{cannot throw}}
495 throw make<const volatile X*>(); // expected-error {{cannot throw}}
499 namespace dr429 { // dr429: yes c++11
500 // FIXME: This rule is obviously intended to apply to C++98 as well.
501 struct A {
502 static void *operator new(size_t, size_t);
503 static void operator delete(void*, size_t);
504 } *a = new (0) A;
505 #if __cplusplus >= 201103L
506 // expected-error@-2 {{'new' expression with placement arguments refers to non-placement 'operator delete'}}
507 // expected-note@-4 {{here}}
508 #endif
509 struct B {
510 static void *operator new(size_t, size_t);
511 static void operator delete(void*);
512 static void operator delete(void*, size_t);
513 } *b = new (0) B; // ok, second delete is not a non-placement deallocation function
516 namespace dr430 { // dr430: yes c++11
517 // resolved by n2239
518 // FIXME: This should apply in C++98 too.
519 void f(int n) {
520 int a[] = { n++, n++, n++ };
521 #if __cplusplus < 201103L
522 // expected-warning@-2 {{multiple unsequenced modifications to 'n'}}
523 #endif
527 namespace dr431 { // dr431: yes
528 struct A {
529 template<typename T> T *get();
530 template<typename T> struct B {
531 template<typename U> U *get();
535 template<typename T> void f(A a) {
536 a.get<A>()->get<T>();
537 a.get<T>()
538 ->get<T>(); // expected-error {{use 'template'}}
539 a.get<T>()->template get<T>();
540 a.A::get<T>();
541 A::B<int> *b = a.get<A::B<int> >();
542 b->get<int>();
543 b->A::B<int>::get<int>();
544 b->A::B<int>::get<T>();
545 b->A::B<T>::get<int>(); // expected-error {{use 'template'}}
546 b->A::B<T>::template get<int>();
547 b->A::B<T>::get<T>(); // expected-error {{use 'template'}}
548 b->A::B<T>::template get<T>();
549 A::B<T> *c = a.get<A::B<T> >();
550 c->get<int>(); // expected-error {{use 'template'}}
551 c->template get<int>();
555 namespace dr432 { // dr432: yes
556 template<typename T> struct A {};
557 template<typename T> struct B : A<B> {}; // expected-error {{requires template arguments}} expected-note {{declared}}
558 template<typename T> struct C : A<C<T> > {};
559 #if __cplusplus >= 201103L
560 template<typename T> struct D : decltype(A<D>()) {}; // expected-error {{requires template arguments}} expected-note {{declared}}
561 #endif
564 namespace dr433 { // dr433: yes
565 template<class T> struct S {
566 void f(union U*);
568 U *p;
569 template<class T> void S<T>::f(union U*) {}
571 S<int> s;
574 namespace dr434 { // dr434: sup 2352
575 void f() {
576 const int ci = 0;
577 int *pi = 0;
578 const int *&rpci = pi; // expected-error {{incompatible qualifiers}}
579 const int * const &rcpci = pi; // OK
580 rpci = &ci;
581 *pi = 1;
584 #if __cplusplus >= 201103L
585 int *pi = 0;
586 const int * const &rcpci = pi;
587 static_assert(&rcpci == &pi, "");
588 #endif
591 // dr435: na
593 namespace dr436 { // dr436: yes
594 enum E { f }; // expected-note {{previous}}
595 void f(); // expected-error {{redefinition}}
598 namespace dr437 { // dr437: sup 1308
599 // This is superseded by 1308, which is in turn superseded by 1330,
600 // which restores this rule.
601 template<typename U> struct T : U {};
602 struct S {
603 void f() throw(S);
604 #if __cplusplus > 201402L
605 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
606 #endif
607 void g() throw(T<S>);
608 #if __cplusplus > 201402L
609 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
610 #endif
611 struct U;
612 void h() throw(U);
613 #if __cplusplus > 201402L
614 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
615 #endif
616 struct U {};
620 // dr438 FIXME write a codegen test
621 // dr439 FIXME write a codegen test
622 // dr441 FIXME write a codegen test
623 // dr442: sup 348
624 // dr443: na
626 namespace dr444 { // dr444: yes
627 struct D;
628 struct B { // expected-note {{candidate function (the implicit copy}} expected-note 0-1 {{implicit move}}
629 D &operator=(D &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
631 struct D : B { // expected-note {{candidate function (the implicit copy}} expected-note 0-1 {{implicit move}}
632 using B::operator=;
633 } extern d;
634 void f() {
635 d = d; // expected-error {{deleted}}
639 namespace dr445 { // dr445: yes
640 class A { void f(); }; // expected-note {{private}}
641 struct B {
642 friend void A::f(); // expected-error {{private}}
646 namespace dr446 { // dr446: yes
647 struct C;
648 struct A {
649 A();
650 A(const A&) = delete; // expected-error 0-1{{extension}} expected-note +{{deleted}}
651 A(const C&);
653 struct C : A {};
654 void f(A a, bool b, C c) {
655 void(b ? a : a);
656 b ? A() : a; // expected-error {{deleted}}
657 b ? a : A(); // expected-error {{deleted}}
658 b ? A() : A();
659 #if __cplusplus <= 201402L
660 // expected-error@-2 {{deleted}}
661 #endif
663 void(b ? a : c);
664 b ? a : C(); // expected-error {{deleted}}
665 b ? c : A();
666 #if __cplusplus <= 201402L
667 // expected-error@-2 {{deleted}}
668 #endif
669 b ? A() : C();
670 #if __cplusplus <= 201402L
671 // expected-error@-2 {{deleted}}
672 #endif
676 namespace dr447 { // dr447: yes
677 struct A { int n; int a[4]; };
678 template<int> struct U {
679 typedef int type;
680 template<typename V> static void h();
682 template<typename T> U<sizeof(T)> g(T);
683 template<typename T, int N> void f(int n) {
684 // ok, not type dependent
685 g(__builtin_offsetof(A, n)).h<int>();
686 g(__builtin_offsetof(T, n)).h<int>();
687 // value dependent if first argument is a dependent type
688 U<__builtin_offsetof(A, n)>::type a;
689 U<__builtin_offsetof(T, n)>::type b; // expected-error +{{}} expected-warning 0+{{}}
690 // as an extension, we allow the member-designator to include array indices
691 g(__builtin_offsetof(A, a[0])).h<int>();
692 g(__builtin_offsetof(A, a[N])).h<int>();
693 U<__builtin_offsetof(A, a[0])>::type c;
694 U<__builtin_offsetof(A, a[N])>::type d; // expected-error +{{}} expected-warning 0+{{}}
698 namespace dr448 { // dr448: yes
699 template<typename T = int> void f(int); // expected-error 0-1{{extension}} expected-note {{no known conversion}}
700 template<typename T> void g(T t) {
701 f<T>(t); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
702 dr448::f(t); // expected-error {{no matching function}}
704 template<typename T> void f(T); // expected-note {{should be declared prior to the call site}}
705 namespace HideFromADL { struct X {}; }
706 template void g(int); // ok
707 template void g(HideFromADL::X); // expected-note {{instantiation of}}
710 // dr449: na
712 namespace dr450 { // dr450: yes
713 typedef int A[3];
714 void f1(const A &);
715 void f2(A &); // expected-note +{{not viable}}
716 struct S { A n; };
717 void g() {
718 f1(S().n);
719 f2(S().n); // expected-error {{no match}}}
721 #if __cplusplus >= 201103L
722 void h() {
723 f1(A{});
724 f2(A{}); // expected-error {{no match}}
726 #endif
729 namespace dr451 { // dr451: yes
730 const int a = 1 / 0; // expected-warning {{undefined}}
731 const int b = 1 / 0; // expected-warning {{undefined}} expected-note {{here}} expected-note 0-1{{division by zero}}
732 int arr[b]; // expected-error +{{variable length arr}} expected-note {{initializer of 'b' is not a constant}}
735 namespace dr452 { // dr452: yes
736 struct A {
737 int a, b, c;
738 A *p;
739 int f();
740 A() : a(f()), b(this->f() + a), c(this->a), p(this) {}
744 // dr454 FIXME write a codegen test
746 namespace dr456 { // dr456: yes
747 // sup 903 c++11
748 const int null = 0;
749 void *p = null;
750 #if __cplusplus >= 201103L
751 // expected-error@-2 {{cannot initialize}}
752 #else
753 // expected-warning@-4 {{null}}
754 #endif
756 const bool f = false;
757 void *q = f;
758 #if __cplusplus >= 201103L
759 // expected-error@-2 {{cannot initialize}}
760 #else
761 // expected-warning@-4 {{null}}
762 #endif
765 namespace dr457 { // dr457: yes
766 const int a = 1;
767 const volatile int b = 1;
768 int ax[a];
769 int bx[b]; // expected-error +{{variable length array}} expected-note {{read of volatile}}
771 enum E {
772 ea = a,
773 eb = b // expected-error {{constant}} expected-note {{read of volatile-qualified}}
777 namespace dr458 { // dr458: 11
778 struct A {
779 int T;
780 int f();
781 template<typename> int g();
784 template<typename> struct B : A {
785 int f();
786 template<typename> int g();
787 template<typename> int h();
790 int A::f() {
791 return T;
793 template<typename T> // expected-note {{declared here}}
794 int A::g() {
795 return T; // expected-error {{'T' does not refer to a value}}
798 template<typename T>
799 int B<T>::f() {
800 return T;
802 template<typename T> template<typename U>
803 int B<T>::g() {
804 return T;
806 template<typename U> template<typename T> // expected-note {{declared here}}
807 int B<U>::h() {
808 return T; // expected-error {{'T' does not refer to a value}}
812 namespace dr460 { // dr460: yes
813 namespace X { namespace Q { int n; } }
814 namespace Y {
815 using X; // expected-error {{requires a qualified name}}
816 using dr460::X; // expected-error {{cannot refer to a namespace}}
817 using X::Q; // expected-error {{cannot refer to a namespace}}
821 // dr461: na
822 // dr462 FIXME write a codegen test
823 // dr463: na
824 // dr464: na
825 // dr465: na
827 namespace dr466 { // dr466: no
828 typedef int I;
829 typedef const int CI;
830 typedef volatile int VI;
831 void f(int *a, CI *b, VI *c) {
832 a->~I();
833 a->~CI();
834 a->~VI();
835 a->I::~I();
836 a->CI::~CI();
837 a->VI::~VI();
839 a->CI::~VI(); // FIXME: This is invalid; CI and VI are not the same scalar type.
841 b->~I();
842 b->~CI();
843 b->~VI();
844 b->I::~I();
845 b->CI::~CI();
846 b->VI::~VI();
848 c->~I();
849 c->~CI();
850 c->~VI();
851 c->I::~I();
852 c->CI::~CI();
853 c->VI::~VI();
857 namespace dr467 { // dr467: yes
858 int stuff();
860 int f() {
861 static bool done;
862 if (done)
863 goto later;
864 static int k = stuff();
865 done = true;
866 later:
867 return k;
869 int g() {
870 goto later; // expected-error {{cannot jump}}
871 int k = stuff(); // expected-note {{bypasses variable initialization}}
872 later:
873 return k;
877 namespace dr468 { // dr468: yes c++11
878 // FIXME: Should we allow this in C++98 too?
879 template<typename> struct A {
880 template<typename> struct B {
881 static int C;
884 int k = dr468::template A<int>::template B<char>::C;
885 #if __cplusplus < 201103L
886 // expected-error@-2 2{{'template' keyword outside of a template}}
887 #endif
890 namespace dr469 { // dr469: no
891 template<typename T> struct X; // expected-note {{here}}
892 template<typename T> struct X<const T> {};
893 X<int&> x; // expected-error {{undefined}}
896 namespace dr470 { // dr470: yes
897 template<typename T> struct A {
898 struct B {};
900 template<typename T> struct C {
903 template struct A<int>; // expected-note {{previous}}
904 template struct A<int>::B; // expected-error {{duplicate explicit instantiation}}
906 // ok, instantiating C<char> doesn't instantiate base class members.
907 template struct A<char>;
908 template struct C<char>;
911 namespace dr471 { // dr471: yes
912 struct A { int n; };
913 struct B : private virtual A {};
914 struct C : protected virtual A {};
915 struct D : B, C { int f() { return n; } };
916 struct E : private virtual A {
917 using A::n;
919 struct F : E, B { int f() { return n; } };
920 struct G : virtual A {
921 private:
922 using A::n; // expected-note {{here}}
924 struct H : B, G { int f() { return n; } }; // expected-error {{private}}
927 namespace dr474 { // dr474: yes
928 namespace N {
929 struct S {
930 void f();
933 void N::S::f() {
934 void g(); // expected-note {{previous}}
936 int g();
937 namespace N {
938 int g(); // expected-error {{cannot be overloaded}}
942 // dr475 FIXME write a codegen test
944 namespace dr477 { // dr477: 3.5
945 struct A {
946 explicit A();
947 virtual void f();
949 struct B {
950 friend explicit A::A(); // expected-error {{'explicit' is invalid in friend declarations}}
951 friend virtual void A::f(); // expected-error {{'virtual' is invalid in friend declarations}}
953 explicit A::A() {} // expected-error {{can only be specified inside the class definition}}
954 virtual void A::f() {} // expected-error {{can only be specified inside the class definition}}
957 namespace dr478 { // dr478: yes
958 struct A { virtual void f() = 0; }; // expected-note {{unimplemented}}
959 void f(A *a);
960 void f(A a[10]); // expected-error {{array of abstract class type}}
963 namespace dr479 { // dr479: yes
964 struct S {
965 S();
966 private:
967 S(const S&); // expected-note +{{here}}
968 ~S(); // expected-note +{{here}}
970 void f() {
971 throw S();
972 // expected-error@-1 {{temporary of type 'S' has private destructor}}
973 // expected-error@-2 {{exception object of type 'S' has private destructor}}
974 #if __cplusplus < 201103L
975 // expected-error@-4 {{C++98 requires an accessible copy constructor}}
976 #endif
977 #if __cplusplus <= 201402L
978 // expected-error@-7 {{calling a private constructor}} (copy ctor)
979 #endif
981 void g() {
982 S s; // expected-error {{private destructor}}}
983 throw s;
984 // expected-error@-1 {{calling a private constructor}}
985 // expected-error@-2 {{exception object of type 'S' has private destructor}}
987 void h() {
988 try {
989 f();
990 g();
991 } catch (S s) {
992 // expected-error@-1 {{calling a private constructor}}
993 // expected-error@-2 {{variable of type 'S' has private destructor}}
998 namespace dr480 { // dr480: yes
999 struct A { int n; };
1000 struct B : A {};
1001 struct C : virtual B {};
1002 struct D : C {};
1004 int A::*a = &A::n;
1005 int D::*b = a; // expected-error {{virtual base}}
1007 extern int D::*c;
1008 int A::*d = static_cast<int A::*>(c); // expected-error {{virtual base}}
1010 D *e;
1011 A *f = e;
1012 D *g = static_cast<D*>(f); // expected-error {{virtual base}}
1014 extern D &i;
1015 A &j = i;
1016 D &k = static_cast<D&>(j); // expected-error {{virtual base}}
1019 namespace dr481 { // dr481: yes
1020 template<class T, T U> class A { T *x; };
1021 T *x; // expected-error {{unknown type}}
1023 template<class T *U> class B { T *x; };
1024 T *y; // ok
1026 struct C {
1027 template<class T> void f(class D *p);
1029 D *z; // ok
1031 template<typename A = C, typename C = A> struct E {
1032 void f() {
1033 typedef ::dr481::C c; // expected-note {{previous}}
1034 typedef C c; // expected-error {{different type}}
1037 template struct E<>; // ok
1038 template struct E<int>; // expected-note {{instantiation of}}
1040 template<template<typename U_no_typo_correction> class A,
1041 A<int> *B,
1042 U_no_typo_correction *C> // expected-error {{unknown type}}
1043 struct F {
1044 U_no_typo_correction *x; // expected-error {{unknown type}}
1047 template<template<class H *> class> struct G {
1048 H *x;
1050 H *q;
1052 typedef int N;
1053 template<N X, typename N, template<N Y> class T> struct I;
1054 template<char*> struct J;
1055 I<123, char*, J> *j;
1058 namespace dr482 { // dr482: 3.5
1059 extern int a;
1060 void f();
1062 int dr482::a = 0; // expected-warning {{extra qualification}}
1063 void dr482::f() {} // expected-warning {{extra qualification}}
1065 inline namespace X { // expected-error 0-1{{C++11 feature}}
1066 extern int b;
1067 void g();
1068 struct S;
1070 int dr482::b = 0; // expected-warning {{extra qualification}}
1071 void dr482::g() {} // expected-warning {{extra qualification}}
1072 struct dr482::S {}; // expected-warning {{extra qualification}}
1074 void dr482::f(); // expected-warning {{extra qualification}}
1075 void dr482::g(); // expected-warning {{extra qualification}}
1077 // FIXME: The following are valid in DR482's wording, but these are bugs in
1078 // the wording which we deliberately don't implement.
1079 namespace N { typedef int type; }
1080 typedef int N::type; // expected-error {{typedef declarator cannot be qualified}}
1081 struct A {
1082 struct B;
1083 struct A::B {}; // expected-error {{extra qualification}}
1085 #if __cplusplus >= 201103L
1086 enum class C;
1087 enum class A::C {}; // expected-error {{extra qualification}}
1088 #endif
1092 namespace dr483 { // dr483: yes
1093 namespace climits {
1094 int check1[__SCHAR_MAX__ >= 127 ? 1 : -1];
1095 int check2[__SHRT_MAX__ >= 32767 ? 1 : -1];
1096 int check3[__INT_MAX__ >= 32767 ? 1 : -1];
1097 int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1];
1098 int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1];
1099 #if __cplusplus < 201103L
1100 // expected-error@-2 1+{{extension}}
1101 #endif
1103 namespace cstdint {
1104 int check1[__PTRDIFF_WIDTH__ >= 16 ? 1 : -1];
1105 int check2[__SIG_ATOMIC_WIDTH__ >= 8 ? 1 : -1];
1106 int check3[__SIZE_WIDTH__ >= 16 ? 1 : -1];
1107 int check4[__WCHAR_WIDTH__ >= 8 ? 1 : -1];
1108 int check5[__WINT_WIDTH__ >= 16 ? 1 : -1];
1112 namespace dr484 { // dr484: yes
1113 struct A {
1114 A();
1115 void f();
1117 typedef const A CA;
1118 void CA::f() {
1119 this->~CA();
1120 this->CA::~A();
1121 this->CA::A::~A();
1123 CA::A() {}
1125 struct B : CA {
1126 B() : CA() {}
1127 void f() { return CA::f(); }
1130 struct C;
1131 typedef C CT; // expected-note {{here}}
1132 struct CT {}; // expected-error {{conflicts with typedef}}
1134 namespace N {
1135 struct D;
1136 typedef D DT; // expected-note {{here}}
1138 struct N::DT {}; // expected-error {{conflicts with typedef}}
1140 typedef struct {
1141 S(); // expected-error {{a type specifier is required}}
1142 } S;
1145 namespace dr485 { // dr485: yes
1146 namespace N {
1147 struct S {};
1148 int operator+(S, S);
1149 template<typename T> int f(S);
1151 template<typename T> int f();
1153 N::S s;
1154 int a = operator+(s, s);
1155 int b = f<int>(s);
1158 namespace dr486 { // dr486: yes
1159 template<typename T> T f(T *); // expected-note 2{{substitution failure}}
1160 int &f(...);
1162 void g();
1163 int n[10];
1165 void h() {
1166 int &a = f(&g);
1167 int &b = f(&n);
1168 f<void()>(&g); // expected-error {{no match}}
1169 f<int[10]>(&n); // expected-error {{no match}}
1173 namespace dr487 { // dr487: yes
1174 enum E { e };
1175 int operator+(int, E); // expected-note 0-1{{here}}
1176 int i[4 + e]; // expected-error 2{{variable length array}} expected-note 0-1{{non-constexpr}}
1179 namespace dr488 { // dr488: yes c++11
1180 template <typename T> void f(T);
1181 void f(int);
1182 void g() {
1183 // FIXME: It seems CWG thought this should be a SFINAE failure prior to
1184 // allowing local types as template arguments. In C++98, we should either
1185 // allow local types as template arguments or treat this as a SFINAE
1186 // failure.
1187 enum E { e };
1188 f(e);
1189 #if __cplusplus < 201103L
1190 // expected-error@-2 {{local type}}
1191 #endif
1195 // dr489: na
1197 namespace dr490 { // dr490: yes
1198 template<typename T> struct X {};
1200 struct A {
1201 typedef int T;
1202 struct K {}; // expected-note {{declared}}
1204 int f(T);
1205 int g(T);
1206 int h(X<T>);
1207 int X<T>::*i(); // expected-note {{previous}}
1208 int K::*j();
1210 template<typename T> T k();
1212 operator X<T>();
1215 struct B {
1216 typedef char T;
1217 typedef int U;
1218 friend int A::f(T);
1219 friend int A::g(U);
1220 friend int A::h(X<T>);
1222 // FIXME: Per this DR, these two are valid! That is another defect
1223 // (no number yet...) which will eventually supersede this one.
1224 friend int X<T>::*A::i(); // expected-error {{return type}}
1225 friend int K::*A::j(); // expected-error {{undeclared identifier 'K'; did you mean 'A::K'?}}
1227 // ok, lookup finds B::T, not A::T, so return type matches
1228 friend char A::k<T>();
1229 friend int A::k<U>();
1231 // A conversion-type-id in a conversion-function-id is always looked up in
1232 // the class of the conversion function first.
1233 friend A::operator X<T>();
1237 namespace dr491 { // dr491: dup 413
1238 struct A {} a, b[3] = { a, {} };
1239 A c[2] = { a, {}, b[1] }; // expected-error {{excess elements}}
1242 // dr492 FIXME write a codegen test
1244 namespace dr493 { // dr493: dup 976
1245 struct X {
1246 template <class T> operator const T &() const;
1248 void f() {
1249 if (X()) {
1254 namespace dr494 { // dr494: dup 372
1255 class A {
1256 class B {};
1257 friend class C;
1259 class C : A::B {
1260 A::B x;
1261 class D : A::B {
1262 A::B y;
1267 namespace dr495 { // dr495: 3.5
1268 template<typename T>
1269 struct S {
1270 operator int() { return T::error; }
1271 template<typename U> operator U();
1273 S<int> s;
1274 long n = s;
1276 template<typename T>
1277 struct S2 {
1278 template<typename U> operator U();
1279 operator int() { return T::error; }
1281 S2<int> s2;
1282 long n2 = s2;
1285 namespace dr496 { // dr496: sup 2094
1286 struct A { int n; };
1287 struct B { volatile int n; };
1288 int check1[ __is_trivially_copyable(const int) ? 1 : -1];
1289 // This checks the dr2094 behavior, not dr496
1290 int check2[ __is_trivially_copyable(volatile int) ? 1 : -1];
1291 int check3[ __is_trivially_constructible(A, const A&) ? 1 : -1];
1292 int check4[ __is_trivially_constructible(B, const B&) ? 1 : -1];
1293 int check5[ __is_trivially_assignable(A, const A&) ? 1 : -1];
1294 int check6[ __is_trivially_assignable(B, const B&) ? 1 : -1];
1297 namespace dr497 { // dr497: sup 253
1298 void before() {
1299 struct S {
1300 mutable int i;
1302 const S cs;
1303 int S::*pm = &S::i;
1304 cs.*pm = 88; // expected-error {{not assignable}}
1307 void after() {
1308 struct S {
1309 S() : i(0) {}
1310 mutable int i;
1312 const S cs;
1313 int S::*pm = &S::i;
1314 cs.*pm = 88; // expected-error {{not assignable}}
1318 namespace dr499 { // dr499: yes
1319 extern char str[];
1320 void f() { throw str; }