Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr0xx.cpp
blob5a127ff4f4164e172ec2afc5e9d3ac436c2c76e4
1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -Wno-bind-to-temporary-copy
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
4 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
5 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
6 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
8 namespace dr1 { // dr1: no
9 namespace X { extern "C" void dr1_f(int a = 1); }
10 namespace Y { extern "C" void dr1_f(int a = 1); }
11 using X::dr1_f; using Y::dr1_f;
12 void g() {
13 dr1_f(0);
14 // FIXME: This should be rejected, due to the ambiguous default argument.
15 dr1_f();
17 namespace X {
18 using Y::dr1_f;
19 void h() {
20 dr1_f(0);
21 // FIXME: This should be rejected, due to the ambiguous default argument.
22 dr1_f();
26 namespace X {
27 void z(int);
29 void X::z(int = 1) {} // expected-note {{previous}}
30 namespace X {
31 void z(int = 1); // expected-error {{redefinition of default argument}}
34 void i(int = 1);
35 void j() {
36 void i(int = 1);
37 using dr1::i;
38 i(0);
39 // FIXME: This should be rejected, due to the ambiguous default argument.
40 i();
42 void k() {
43 using dr1::i;
44 void i(int = 1);
45 i(0);
46 // FIXME: This should be rejected, due to the ambiguous default argument.
47 i();
51 namespace dr3 { // dr3: yes
52 template<typename T> struct A {};
53 template<typename T> void f(T) { A<T> a; } // expected-note {{implicit instantiation}}
54 template void f(int);
55 template<> struct A<int> {}; // expected-error {{explicit specialization of 'dr3::A<int>' after instantiation}}
58 namespace dr4 { // dr4: yes
59 extern "C" {
60 static void dr4_f(int) {}
61 static void dr4_f(float) {}
62 void dr4_g(int) {} // expected-note {{previous}}
63 void dr4_g(float) {} // expected-error {{conflicting types}}
67 namespace dr5 { // dr5: yes
68 struct A {} a;
69 struct B {
70 B(const A&);
71 B(const B&);
73 const volatile B b = a;
75 struct C { C(C&); };
76 struct D : C {};
77 struct E { operator D&(); } e;
78 const C c = e;
81 namespace dr7 { // dr7: yes
82 class A { public: ~A(); };
83 class B : virtual private A {}; // expected-note 2 {{declared private here}}
84 class C : public B {} c; // expected-error 2 {{inherited virtual base class 'A' has private destructor}} \
85 // expected-note {{implicit default constructor for 'dr7::C' first required here}} \
86 // expected-note {{implicit destructor for 'dr7::C' first required here}}
87 class VeryDerivedC : public B, virtual public A {} vdc;
89 class X { ~X(); }; // expected-note {{here}}
90 class Y : X { ~Y() {} }; // expected-error {{private destructor}}
92 namespace PR16370 { // This regressed the first time DR7 was fixed.
93 struct S1 { virtual ~S1(); };
94 struct S2 : S1 {};
95 struct S3 : S2 {};
96 struct S4 : virtual S2 {};
97 struct S5 : S3, S4 {
98 S5();
99 ~S5();
101 S5::S5() {}
105 namespace dr8 { // dr8: dup 45
106 class A {
107 struct U;
108 static const int k = 5;
109 void f();
110 template<typename, int, void (A::*)()> struct T;
112 T<U, k, &A::f> *g();
114 A::T<A::U, A::k, &A::f> *A::g() { return 0; }
117 namespace dr9 { // dr9: yes
118 struct B {
119 protected:
120 int m; // expected-note {{here}}
121 friend int R1();
123 struct N : protected B { // expected-note {{protected}}
124 friend int R2();
125 } n;
126 int R1() { return n.m; } // expected-error {{protected member}}
127 int R2() { return n.m; }
130 namespace dr10 { // dr10: dup 45
131 class A {
132 struct B {
133 A::B *p;
138 namespace dr11 { // dr11: yes
139 template<typename T> struct A : T {
140 using typename T::U;
141 U u;
143 template<typename T> struct B : T {
144 using T::V;
145 V v; // expected-error {{unknown type name}}
147 struct X { typedef int U; };
148 A<X> ax;
151 namespace dr12 { // dr12: sup 239
152 enum E { e };
153 E &f(E, E = e);
154 void g() {
155 int &f(int, E = e);
156 // Under DR12, these call two different functions.
157 // Under DR239, they call the same function.
158 int &b = f(e);
159 int &c = f(1);
163 namespace dr13 { // dr13: no
164 extern "C" void f(int);
165 void g(char);
167 template<typename T> struct A {
168 A(void (*fp)(T));
170 template<typename T> int h(void (T));
172 A<int> a1(f); // FIXME: We should reject this.
173 A<char> a2(g);
174 int a3 = h(f); // FIXME: We should reject this.
175 int a4 = h(g);
178 namespace dr14 { // dr14: yes
179 namespace X { extern "C" int dr14_f(); }
180 namespace Y { extern "C" int dr14_f(); }
181 using namespace X;
182 using namespace Y;
183 int k = dr14_f();
185 class C {
186 int k;
187 friend int Y::dr14_f();
188 } c;
189 namespace Z {
190 extern "C" int dr14_f() { return c.k; }
193 namespace X { typedef int T; typedef int U; } // expected-note {{candidate}}
194 namespace Y { typedef int T; typedef long U; } // expected-note {{candidate}}
195 T t; // ok, same type both times
196 U u; // expected-error {{ambiguous}}
199 namespace dr15 { // dr15: yes
200 template<typename T> void f(int); // expected-note {{previous}}
201 template<typename T> void f(int = 0); // expected-error {{default arguments cannot be added}}
204 namespace dr16 { // dr16: yes
205 class A { // expected-note {{here}}
206 void f(); // expected-note {{here}}
207 friend class C;
209 class B : A {}; // expected-note 3{{here}}
210 class C : B {
211 void g() {
212 f(); // expected-error {{private member}}
213 A::f(); // expected-error {{private member}} expected-error {{private base}}
218 namespace dr17 { // dr17: yes
219 class A {
220 int n;
221 int f();
222 struct C;
224 struct B : A {} b;
225 int A::f() { return b.n; }
226 struct A::C : A {
227 int g() { return n; }
231 // dr18: sup 577
233 namespace dr19 { // dr19: yes
234 struct A {
235 int n; // expected-note {{here}}
237 struct B : protected A { // expected-note {{here}}
239 struct C : B {} c;
240 struct D : B {
241 int get1() { return c.n; } // expected-error {{protected member}}
242 int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here
246 namespace dr20 { // dr20: yes
247 class X {
248 public:
249 X();
250 private:
251 X(const X&); // expected-note {{here}}
253 X &f();
254 X x = f(); // expected-error {{private}}
257 namespace dr21 { // dr21: yes
258 template<typename T> struct A;
259 struct X {
260 template<typename T = int> friend struct A; // expected-error {{default template argument not permitted on a friend template}}
261 template<typename T = int> friend struct B; // expected-error {{default template argument not permitted on a friend template}}
265 namespace dr22 { // dr22: sup 481
266 template<typename dr22_T = dr22_T> struct X; // expected-error {{unknown type name 'dr22_T'}}
267 typedef int T;
268 template<typename T = T> struct Y;
271 namespace dr23 { // dr23: yes
272 template<typename T> void f(T, T); // expected-note {{candidate}}
273 template<typename T> void f(T, int); // expected-note {{candidate}}
274 void g() { f(0, 0); } // expected-error {{ambiguous}}
277 // dr24: na
279 namespace dr25 { // dr25: yes
280 struct A {
281 void f() throw(int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
283 void (A::*f)() throw (int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
284 void (A::*g)() throw () = f;
285 #if __cplusplus <= 201402L
286 // expected-error@-2 {{is not superset of source}}
287 #else
288 // expected-error@-4 {{different exception specifications}}
289 #endif
290 void (A::*g2)() throw () = 0;
291 void (A::*h)() throw (int, char) = f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
292 void (A::*i)() throw () = &A::f;
293 #if __cplusplus <= 201402L
294 // expected-error@-2 {{is not superset of source}}
295 #else
296 // expected-error@-4 {{different exception specifications}}
297 #endif
298 void (A::*i2)() throw () = 0;
299 void (A::*j)() throw (int, char) = &A::f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
300 void x() {
301 g2 = f;
302 #if __cplusplus <= 201402L
303 // expected-error@-2 {{is not superset of source}}
304 #else
305 // expected-error@-4 {{different exception specifications}}
306 #endif
307 h = f;
308 i2 = &A::f;
309 #if __cplusplus <= 201402L
310 // expected-error@-2 {{is not superset of source}}
311 #else
312 // expected-error@-4 {{different exception specifications}}
313 #endif
314 j = &A::f;
318 namespace dr26 { // dr26: yes
319 struct A { A(A, const A & = A()); }; // expected-error {{must pass its first argument by reference}}
320 struct B {
321 B();
322 // FIXME: In C++98, we diagnose this twice.
323 B(const B &, B = B());
324 #if __cplusplus <= 201402L
325 // expected-error@-2 1+{{recursive evaluation of default argument}} expected-note@-2 1+{{used here}}
326 #endif
328 struct C {
329 static C &f();
330 C(const C &, C = f()); // expected-error {{recursive evaluation of default argument}} expected-note {{used here}}
334 namespace dr27 { // dr27: yes
335 enum E { e } n;
336 E &m = true ? n : n;
339 // dr28: na lib
341 namespace dr29 { // dr29: 3.4
342 void dr29_f0(); // expected-note {{here}}
343 void g0() { void dr29_f0(); }
344 extern "C++" void g0_cxx() { void dr29_f0(); }
345 extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}}
347 extern "C" void dr29_f1(); // expected-note {{here}}
348 void g1() { void dr29_f1(); }
349 extern "C" void g1_c() { void dr29_f1(); }
350 extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}}
352 void g2() { void dr29_f2(); } // expected-note {{here}}
353 extern "C" void dr29_f2(); // expected-error {{different language linkage}}
355 extern "C" void g3() { void dr29_f3(); } // expected-note {{here}}
356 extern "C++" void dr29_f3(); // expected-error {{different language linkage}}
358 extern "C++" void g4() { void dr29_f4(); } // expected-note {{here}}
359 extern "C" void dr29_f4(); // expected-error {{different language linkage}}
361 extern "C" void g5();
362 extern "C++" void dr29_f5();
363 void g5() {
364 void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
367 extern "C++" void g6();
368 extern "C" void dr29_f6();
369 void g6() {
370 void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
373 extern "C" void g7();
374 extern "C++" void dr29_f7(); // expected-note {{here}}
375 extern "C" void g7() {
376 void dr29_f7(); // expected-error {{different language linkage}}
379 extern "C++" void g8();
380 extern "C" void dr29_f8(); // expected-note {{here}}
381 extern "C++" void g8() {
382 void dr29_f8(); // expected-error {{different language linkage}}
386 namespace dr30 { // dr30: sup 468 c++11
387 struct A {
388 template<int> static int f();
389 } a, *p = &a;
390 int x = A::template f<0>();
391 int y = a.template f<0>();
392 int z = p->template f<0>();
393 #if __cplusplus < 201103L
394 // FIXME: It's not clear whether DR468 applies to C++98 too.
395 // expected-error@-5 {{'template' keyword outside of a template}}
396 // expected-error@-5 {{'template' keyword outside of a template}}
397 // expected-error@-5 {{'template' keyword outside of a template}}
398 #endif
401 namespace dr31 { // dr31: yes
402 class X {
403 private:
404 void operator delete(void*); // expected-note {{here}}
406 // We would call X::operator delete if X() threw (even though it can't,
407 // and even though we allocated the X using ::operator delete).
408 X *p = new X; // expected-error {{private}}
411 // dr32: na
413 namespace dr33 { // dr33: yes
414 namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}}
415 namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}}
416 void g(X::S);
417 template<typename Z> Z g(Y::T);
418 void h() { f(&g); } // expected-error {{ambiguous}}
420 template<typename T> void t(X::S);
421 template<typename T, typename U = void> void u(X::S); // expected-error 0-1{{default template argument}}
422 void templ() { f(t<int>); f(u<int>); }
424 // Even though v<int> cannot select the first overload, ADL considers it
425 // and adds namespace Z to the set of associated namespaces, and then picks
426 // Z::f even though that function has nothing to do with any associated type.
427 namespace Z { struct Q; void f(void(*)()); }
428 template<int> Z::Q v();
429 template<typename> void v();
430 void unrelated_templ() { f(v<int>); }
432 namespace dependent {
433 struct X {};
434 template<class T> struct Y {
435 friend int operator+(X, void(*)(Y)) {}
438 template<typename T> void f(Y<T>);
439 int use = X() + f<int>; // expected-error {{invalid operands}}
442 namespace member {
443 struct Q {};
444 struct Y { friend int operator+(Q, Y (*)()); };
445 struct X { template<typename> static Y f(); };
446 int m = Q() + X().f<int>; // ok
447 int n = Q() + (&(X().f<int>)); // ok
451 // dr34: na
452 // dr35: dup 178
454 namespace dr36 { // dr36: yes
455 namespace example1 {
456 namespace A {
457 int i;
460 namespace A1 {
461 using A::i;
462 using A::i;
465 void f()
467 using A::i;
468 using A::i;
472 namespace example2 {
473 struct A
475 int i;
476 static int j;
479 struct B : A { };
480 struct C : A { };
482 struct D : virtual B, virtual C
484 using B::i; // expected-note {{previous using declaration}}
485 using B::i; // expected-error {{redeclaration of using declaration}}
487 using C::i; // expected-note {{previous using declaration}}
488 using C::i; // expected-error {{redeclaration of using declaration}}
490 using B::j; // expected-note {{previous using declaration}}
491 using B::j; // expected-error {{redeclaration of using declaration}}
493 using C::j; // expected-note {{previous using declaration}}
494 using C::j; // expected-error {{redeclaration of using declaration}}
498 namespace example3 {
499 template<typename T>
500 struct A
502 T i;
503 static T j;
506 template<typename T>
507 struct B : A<T> { };
508 template<typename T>
509 struct C : A<T> { };
511 template<typename T>
512 struct D : virtual B<T>, virtual C<T>
514 using B<T>::i; // expected-note {{previous using declaration}}
515 using B<T>::i; // expected-error {{redeclaration of using declaration}}
517 using C<T>::i; // expected-note {{previous using declaration}}
518 using C<T>::i; // expected-error {{redeclaration of using declaration}}
520 using B<T>::j; // expected-note {{previous using declaration}}
521 using B<T>::j; // expected-error {{redeclaration of using declaration}}
523 using C<T>::j; // expected-note {{previous using declaration}}
524 using C<T>::j; // expected-error {{redeclaration of using declaration}}
527 namespace example4 {
528 template<typename T>
529 struct E {
530 T k;
533 template<typename T>
534 struct G : E<T> {
535 using E<T>::k; // expected-note {{previous using declaration}}
536 using E<T>::k; // expected-error {{redeclaration of using declaration}}
541 // dr37: sup 475
543 namespace dr38 { // dr38: yes
544 template<typename T> struct X {};
545 template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }
546 template X<int> operator+<int>(X<int>, X<int>);
549 namespace dr39 { // dr39: no
550 namespace example1 {
551 struct A { int &f(int); };
552 struct B : A {
553 using A::f;
554 float &f(float);
555 } b;
556 int &r = b.f(0);
559 namespace example2 {
560 struct A {
561 int &x(int); // expected-note {{found}}
562 static int &y(int); // expected-note {{found}}
564 struct V {
565 int &z(int);
567 struct B : A, virtual V {
568 using A::x; // expected-note {{found}}
569 float &x(float);
570 using A::y; // expected-note {{found}}
571 static float &y(float);
572 using V::z;
573 float &z(float);
575 struct C : A, B, virtual V {} c; // expected-warning {{direct base 'A' is inaccessible due to ambiguity:\n struct dr39::example2::C -> A\n struct dr39::example2::C -> B -> A}}
576 int &x = c.x(0); // expected-error {{found in multiple base classes}}
577 // FIXME: This is valid, because we find the same static data member either way.
578 int &y = c.y(0); // expected-error {{found in multiple base classes}}
579 int &z = c.z(0);
582 namespace example3 {
583 struct A { static int f(); };
584 struct B : virtual A { using A::f; };
585 struct C : virtual A { using A::f; };
586 struct D : B, C {} d;
587 int k = d.f();
590 namespace example4 {
591 struct A { int n; }; // expected-note {{found}}
592 struct B : A {};
593 struct C : A {};
594 struct D : B, C { int f() { return n; } }; // expected-error {{found in multiple base-class}}
597 namespace PR5916 {
598 // FIXME: This is valid.
599 struct A { int n; }; // expected-note +{{found}}
600 struct B : A {};
601 struct C : A {};
602 struct D : B, C {};
603 int k = sizeof(D::n); // expected-error {{found in multiple base}} expected-error {{unknown type name}}
604 #if __cplusplus >= 201103L
605 decltype(D::n) n; // expected-error {{found in multiple base}}
606 #endif
610 // dr40: na
612 namespace dr41 { // dr41: yes
613 struct S f(S);
616 namespace dr42 { // dr42: yes
617 struct A { static const int k = 0; };
618 struct B : A { static const int k = A::k; };
621 // dr43: na
623 namespace dr44 { // dr44: sup 727
624 struct A {
625 template<int> void f();
626 template<> void f<0>();
630 namespace dr45 { // dr45: yes
631 class A {
632 class B {};
633 class C : B {};
634 C c;
638 namespace dr46 { // dr46: yes
639 template<typename> struct A { template<typename> struct B {}; };
640 template template struct A<int>::B<int>; // expected-error {{expected unqualified-id}}
643 namespace dr47 { // dr47: sup 329
644 template<typename T> struct A {
645 friend void f() { T t; } // expected-error {{redefinition}} expected-note {{previous}}
647 A<int> a;
648 A<float> b; // expected-note {{instantiation of}}
650 void f();
651 void g() { f(); }
654 namespace dr48 { // dr48: yes
655 namespace {
656 struct S {
657 static const int m = 0;
658 static const int n = 0;
659 static const int o = 0;
662 int a = S::m;
663 // FIXME: We should produce a 'has internal linkage but is not defined'
664 // diagnostic for 'S::n'.
665 const int &b = S::n;
666 const int S::o;
667 const int &c = S::o;
670 namespace dr49 { // dr49: yes
671 template<int*> struct A {}; // expected-note 0-2{{here}}
672 int k;
673 #if __has_feature(cxx_constexpr)
674 constexpr
675 #endif
676 int *const p = &k; // expected-note 0-2{{here}}
677 A<&k> a;
678 A<p> b;
679 #if __cplusplus <= 201402L
680 // expected-error@-2 {{must have its address taken}}
681 #endif
682 #if __cplusplus < 201103L
683 // expected-error@-5 {{internal linkage}}
684 #endif
685 int *q = &k;
686 A<q> c;
687 #if __cplusplus < 201103L
688 // expected-error@-2 {{must have its address taken}}
689 #else
690 // expected-error@-4 {{constant expression}}
691 // expected-note@-5 {{read of non-constexpr}}
692 // expected-note@-7 {{declared here}}
693 #endif
696 namespace dr50 { // dr50: yes
697 struct X; // expected-note {{forward}}
698 extern X *p;
699 X *q = (X*)p;
700 X *r = static_cast<X*>(p);
701 X *s = const_cast<X*>(p);
702 X *t = reinterpret_cast<X*>(p);
703 X *u = dynamic_cast<X*>(p); // expected-error {{incomplete}}
706 namespace dr51 { // dr51: yes
707 struct A {};
708 struct B : A {};
709 struct S {
710 operator A&();
711 operator B&();
712 } s;
713 A &a = s;
716 namespace dr52 { // dr52: yes
717 struct A { int n; }; // expected-note {{here}}
718 struct B : private A {} b; // expected-note 2{{private}}
719 // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
720 int k = b.A::n; // expected-error {{'A' is a private member of 'dr52::A'}}
721 // expected-error@-1 {{cannot cast 'struct B' to its private base}}
724 namespace dr53 { // dr53: yes
725 int n = 0;
726 enum E { e } x = static_cast<E>(n);
729 namespace dr54 { // dr54: yes
730 struct A { int a; } a;
731 struct V { int v; } v;
732 struct B : private A, virtual V { int b; } b; // expected-note 6{{private here}}
734 A &sab = static_cast<A&>(b); // expected-error {{private base}}
735 A *spab = static_cast<A*>(&b); // expected-error {{private base}}
736 int A::*smab = static_cast<int A::*>(&B::b); // expected-error {{private base}}
737 B &sba = static_cast<B&>(a); // expected-error {{private base}}
738 B *spba = static_cast<B*>(&a); // expected-error {{private base}}
739 int B::*smba = static_cast<int B::*>(&A::a); // expected-error {{private base}}
741 V &svb = static_cast<V&>(b);
742 V *spvb = static_cast<V*>(&b);
743 int V::*smvb = static_cast<int V::*>(&B::b); // expected-error {{virtual base}}
744 B &sbv = static_cast<B&>(v); // expected-error {{virtual base}}
745 B *spbv = static_cast<B*>(&v); // expected-error {{virtual base}}
746 int B::*smbv = static_cast<int B::*>(&V::v); // expected-error {{virtual base}}
748 A &cab = (A&)(b);
749 A *cpab = (A*)(&b);
750 int A::*cmab = (int A::*)(&B::b);
751 B &cba = (B&)(a);
752 B *cpba = (B*)(&a);
753 int B::*cmba = (int B::*)(&A::a);
755 V &cvb = (V&)(b);
756 V *cpvb = (V*)(&b);
757 int V::*cmvb = (int V::*)(&B::b); // expected-error {{virtual base}}
758 B &cbv = (B&)(v); // expected-error {{virtual base}}
759 B *cpbv = (B*)(&v); // expected-error {{virtual base}}
760 int B::*cmbv = (int B::*)(&V::v); // expected-error {{virtual base}}
763 namespace dr55 { // dr55: yes
764 enum E { e = 5 };
765 int test[(e + 1 == 6) ? 1 : -1];
768 namespace dr56 { // dr56: yes
769 struct A {
770 typedef int T; // expected-note {{previous}}
771 typedef int T; // expected-error {{redefinition}}
773 struct B {
774 struct X;
775 typedef X X; // expected-note {{previous}}
776 typedef X X; // expected-error {{redefinition}}
780 namespace dr58 { // dr58: yes
781 // FIXME: Ideally, we should have a CodeGen test for this.
782 #if __cplusplus >= 201103L
783 enum E1 { E1_0 = 0, E1_1 = 1 };
784 enum E2 { E2_0 = 0, E2_m1 = -1 };
785 struct X { E1 e1 : 1; E2 e2 : 1; };
786 static_assert(X{E1_1, E2_m1}.e1 == 1, "");
787 static_assert(X{E1_1, E2_m1}.e2 == -1, "");
788 #endif
791 namespace dr59 { // dr59: yes
792 #pragma clang diagnostic push
793 #pragma clang diagnostic ignored "-Wdeprecated-volatile"
794 template<typename T> struct convert_to { operator T() const; };
795 struct A {}; // expected-note 5+{{candidate}}
796 struct B : A {}; // expected-note 0+{{candidate}}
798 A a1 = convert_to<A>();
799 A a2 = convert_to<A&>();
800 A a3 = convert_to<const A>();
801 A a4 = convert_to<const volatile A>();
802 #if __cplusplus <= 201402L
803 // expected-error@-2 {{no viable}}
804 #endif
805 A a5 = convert_to<const volatile A&>(); // expected-error {{no viable}}
807 B b1 = convert_to<B>();
808 B b2 = convert_to<B&>();
809 B b3 = convert_to<const B>();
810 B b4 = convert_to<const volatile B>();
811 #if __cplusplus <= 201402L
812 // expected-error@-2 {{no viable}}
813 #endif
814 B b5 = convert_to<const volatile B&>(); // expected-error {{no viable}}
816 A c1 = convert_to<B>();
817 A c2 = convert_to<B&>();
818 A c3 = convert_to<const B>();
819 A c4 = convert_to<const volatile B>(); // expected-error {{no viable}}
820 A c5 = convert_to<const volatile B&>(); // expected-error {{no viable}}
822 int n1 = convert_to<int>();
823 int n2 = convert_to<int&>();
824 int n3 = convert_to<const int>();
825 int n4 = convert_to<const volatile int>();
826 int n5 = convert_to<const volatile int&>();
827 #pragma clang diagnostic pop
830 namespace dr60 { // dr60: yes
831 void f(int &);
832 int &f(...);
833 const int k = 0;
834 int &n = f(k);
837 namespace dr61 { // dr61: yes
838 struct X {
839 static void f();
840 } x;
841 struct Y {
842 static void f();
843 static void f(int);
844 } y;
845 // This is (presumably) valid, because x.f does not refer to an overloaded
846 // function name.
847 void (*p)() = &x.f;
848 void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}}
849 void (*r)() = y.f; // expected-error {{cannot create a non-constant pointer to member function}}
852 namespace dr62 { // dr62: yes
853 struct A {
854 struct { int n; } b;
856 template<typename T> struct X {};
857 template<typename T> T get() { return get<T>(); }
858 template<typename T> int take(T) { return 0; }
860 X<A> x1;
861 A a = get<A>();
863 typedef struct { } *NoNameForLinkagePtr;
864 #if __cplusplus < 201103L
865 // expected-note@-2 5{{here}}
866 #endif
867 NoNameForLinkagePtr noNameForLinkagePtr;
869 struct Danger {
870 NoNameForLinkagePtr p;
873 X<NoNameForLinkagePtr> x2;
874 X<const NoNameForLinkagePtr> x3;
875 NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>();
876 NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>();
877 int n1 = take(noNameForLinkagePtr);
878 #if __cplusplus < 201103L
879 // expected-error@-6 {{uses unnamed type}}
880 // expected-error@-6 {{uses unnamed type}}
881 // expected-error@-6 {{uses unnamed type}}
882 // expected-error@-6 {{uses unnamed type}}
883 // expected-error@-6 {{uses unnamed type}}
884 #endif
886 X<Danger> x4;
888 void f() {
889 struct NoLinkage {};
890 X<NoLinkage> a;
891 X<const NoLinkage> b;
892 get<NoLinkage>();
893 get<const NoLinkage>();
894 X<void (*)(NoLinkage A::*)> c;
895 X<int NoLinkage::*> d;
896 #if __cplusplus < 201103L
897 // expected-error@-7 {{uses local type}}
898 // expected-error@-7 {{uses local type}}
899 // expected-error@-7 {{uses local type}}
900 // expected-error@-7 {{uses local type}}
901 // expected-error@-7 {{uses local type}}
902 // expected-error@-7 {{uses local type}}
903 #endif
907 namespace dr63 { // dr63: yes
908 template<typename T> struct S { typename T::error e; };
909 extern S<int> *p;
910 void *q = p;
913 namespace dr64 { // dr64: yes
914 template<class T> void f(T);
915 template<class T> void f(T*);
916 template<> void f(int*);
917 template<> void f<int>(int*);
918 template<> void f(int);
921 // dr65: na
923 namespace dr66 { // dr66: no
924 namespace X {
925 int f(int n); // expected-note 2{{candidate}}
927 using X::f;
928 namespace X {
929 int f(int n = 0);
930 int f(int, int);
932 // FIXME: The first two calls here should be accepted.
933 int a = f(); // expected-error {{no matching function}}
934 int b = f(1);
935 int c = f(1, 2); // expected-error {{no matching function}}
938 // dr67: na
940 namespace dr68 { // dr68: yes
941 template<typename T> struct X {};
942 struct ::dr68::X<int> x1;
943 struct ::dr68::template X<int> x2;
944 #if __cplusplus < 201103L
945 // expected-error@-2 {{'template' keyword outside of a template}}
946 #endif
947 struct Y {
948 friend struct X<int>;
949 friend struct ::dr68::X<char>;
950 friend struct ::dr68::template X<double>;
951 #if __cplusplus < 201103L
952 // expected-error@-2 {{'template' keyword outside of a template}}
953 #endif
955 template<typename>
956 struct Z {
957 friend struct ::dr68::template X<double>;
958 friend typename ::dr68::X<double>;
959 #if __cplusplus < 201103L
960 // expected-error@-2 {{C++11 extension}}
961 #endif
965 namespace dr69 { // dr69: yes
966 template<typename T> static void f() {} // #dr69-f
967 // FIXME: Should we warn here?
968 inline void g() { f<int>(); }
969 extern template void f<char>(); // expected-error {{explicit instantiation declaration of 'f' with internal linkage}}
970 #if __cplusplus < 201103L
971 // expected-error@-2 {{C++11 extension}}
972 #endif
973 template<void(*)()> struct Q {};
974 Q<&f<int> > q;
975 #if __cplusplus < 201103L
976 // expected-error@-2 {{internal linkage}} expected-note@#dr69-f {{here}}
977 #endif
980 namespace dr70 { // dr70: yes
981 template<int> struct A {};
982 template<int I, int J> int f(int (&)[I + J], A<I>, A<J>);
983 int arr[7];
984 int k = f(arr, A<3>(), A<4>());
987 // dr71: na
988 // dr72: dup 69
990 #if __cplusplus >= 201103L
991 namespace dr73 { // dr73: sup 1652
992 int a, b;
993 static_assert(&a + 1 != &b, ""); // expected-error {{not an integral constant expression}}
994 // expected-note@-1 {{comparison against pointer '&a + 1' that points past the end of a complete object}}
996 #endif
998 namespace dr74 { // dr74: yes
999 enum E { k = 5 };
1000 int (*p)[k] = new int[k][k];
1003 namespace dr75 { // dr75: yes
1004 struct S {
1005 static int n = 0; // expected-error {{non-const}}
1009 namespace dr76 { // dr76: yes
1010 const volatile int n = 1;
1011 int arr[n]; // expected-error +{{variable length array}} expected-note {{read of volatile}}
1014 namespace dr77 { // dr77: yes
1015 struct A {
1016 struct B {};
1017 friend struct B;
1021 namespace dr78 { // dr78: sup ????
1022 // Under DR78, this is valid, because 'k' has static storage duration, so is
1023 // zero-initialized.
1024 const int k; // expected-error {{default initialization of an object of const}}
1027 // dr79: na
1029 namespace dr80 { // dr80: yes
1030 struct A {
1031 int A;
1033 struct B {
1034 static int B; // expected-error {{same name as its class}}
1036 struct C {
1037 int C; // expected-error {{same name as its class}}
1038 C();
1040 struct D {
1041 D();
1042 int D; // expected-error {{same name as its class}}
1046 // dr81: na
1047 // dr82: dup 48
1049 namespace dr83 { // dr83: yes
1050 int &f(const char*);
1051 char &f(char *);
1052 int &k = f("foo");
1055 namespace dr84 { // dr84: yes
1056 struct B;
1057 struct A { operator B() const; };
1058 struct C {};
1059 struct B {
1060 B(B&); // expected-note 0-1{{candidate}}
1061 B(C); // expected-note 0-1{{no known conversion from 'B' to 'C'}}
1062 operator C() const;
1064 A a;
1065 // Cannot use B(C) / operator C() pair to construct the B from the B temporary
1066 // here. In C++17, we initialize the B object directly using 'A::operator B()'.
1067 B b = a;
1068 #if __cplusplus <= 201402L
1069 // expected-error@-2 {{no viable}}
1070 #endif
1073 namespace dr85 { // dr85: yes
1074 struct A {
1075 struct B;
1076 struct B {}; // expected-note{{previous declaration is here}}
1077 struct B; // expected-error{{class member cannot be redeclared}}
1079 union U;
1080 union U {}; // expected-note{{previous declaration is here}}
1081 union U; // expected-error{{class member cannot be redeclared}}
1083 #if __cplusplus >= 201103L
1084 enum E1 : int;
1085 enum E1 : int { e1 }; // expected-note{{previous declaration is here}}
1086 enum E1 : int; // expected-error{{class member cannot be redeclared}}
1088 enum class E2;
1089 enum class E2 { e2 }; // expected-note{{previous declaration is here}}
1090 enum class E2; // expected-error{{class member cannot be redeclared}}
1091 #endif
1094 template <typename T>
1095 struct C {
1096 struct B {}; // expected-note{{previous declaration is here}}
1097 struct B; // expected-error{{class member cannot be redeclared}}
1101 // dr86: dup 446
1103 namespace dr87 { // dr87: no
1104 // FIXME: Superseded by dr1975
1105 template<typename T> struct X {};
1106 // FIXME: This is invalid.
1107 X<void() throw()> x;
1108 // This is valid under dr87 but not under dr1975.
1109 X<void(void() throw())> y;
1112 namespace dr88 { // dr88: yes
1113 template<typename T> struct S {
1114 static const int a = 1; // expected-note {{previous}}
1115 static const int b;
1117 template<> const int S<int>::a = 4; // expected-error {{already has an initializer}}
1118 template<> const int S<int>::b = 4;
1121 // dr89: na
1123 namespace dr90 { // dr90: yes
1124 struct A {
1125 template<typename T> friend void dr90_f(T);
1127 struct B : A {
1128 template<typename T> friend void dr90_g(T);
1129 struct C {};
1130 union D {};
1132 struct E : B {};
1133 struct F : B::C {};
1135 void test() {
1136 dr90_f(A());
1137 dr90_f(B());
1138 dr90_f(B::C()); // expected-error {{undeclared identifier}}
1139 dr90_f(B::D()); // expected-error {{undeclared identifier}}
1140 dr90_f(E());
1141 dr90_f(F()); // expected-error {{undeclared identifier}}
1143 dr90_g(A()); // expected-error {{undeclared identifier}}
1144 dr90_g(B());
1145 dr90_g(B::C());
1146 dr90_g(B::D());
1147 dr90_g(E());
1148 dr90_g(F()); // expected-error {{undeclared identifier}}
1152 namespace dr91 { // dr91: yes
1153 union U { friend int f(U); };
1154 int k = f(U());
1157 namespace dr92 { // dr92: 4 c++17
1158 void f() throw(int, float); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1159 void (*p)() throw(int) = &f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1160 #if __cplusplus <= 201402L
1161 // expected-error@-2 {{target exception specification is not superset of source}}
1162 #else
1163 // expected-warning@-4 {{target exception specification is not superset of source}}
1164 #endif
1165 void (*q)() throw(int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1166 void (**pp)() throw() = &q;
1167 #if __cplusplus <= 201402L
1168 // expected-error@-2 {{exception specifications are not allowed}}
1169 #else
1170 // expected-error@-4 {{cannot initialize}}
1171 #endif
1173 void g(void() throw()); // expected-note 0-2 {{no known conversion}} expected-warning 0-1{{mangled name of 'g' will change in C++17}}
1174 void h() throw() {
1175 g(f); // expected-error-re {{{{is not superset|no matching function}}}}
1176 g(q); // expected-error-re {{{{is not superset|no matching function}}}}
1179 // Prior to C++17, this is OK because the exception specification is not
1180 // considered in this context. In C++17, we *do* perform an implicit
1181 // conversion (which performs initialization), and the exception specification
1182 // is part of the type of the parameter, so this is invalid.
1183 template<void() throw()> struct X {};
1184 X<&f> xp;
1185 #if __cplusplus > 201402L
1186 // expected-error@-2 {{not implicitly convertible}}
1187 #endif
1189 template<void() throw(int)> struct Y {}; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}}
1190 Y<&h> yp; // ok
1193 // dr93: na
1195 namespace dr94 { // dr94: yes
1196 struct A { static const int n = 5; };
1197 int arr[A::n];
1200 namespace dr95 { // dr95: yes
1201 struct A;
1202 struct B;
1203 namespace N {
1204 class C {
1205 friend struct A;
1206 friend struct B;
1207 static void f(); // expected-note {{here}}
1209 struct A *p; // dr95::A, not dr95::N::A.
1211 A *q = N::p; // ok, same type
1212 struct B { void f() { N::C::f(); } }; // expected-error {{private}}
1215 namespace dr96 { // dr96: no
1216 struct A {
1217 void f(int);
1218 template<typename T> int f(T);
1219 template<typename T> struct S {};
1220 } a;
1221 template<template<typename> class X> struct B {};
1223 template<typename T>
1224 void test() {
1225 int k1 = a.template f<int>(0);
1226 // FIXME: This is ill-formed, because 'f' is not a template-id and does not
1227 // name a class template.
1228 // FIXME: What about alias templates?
1229 int k2 = a.template f(1);
1230 A::template S<int> s;
1231 B<A::template S> b;
1235 namespace dr97 { // dr97: yes
1236 struct A {
1237 static const int a = false;
1238 static const int b = !a;
1242 namespace dr98 { // dr98: yes
1243 void test(int n) {
1244 switch (n) {
1245 try { // expected-note 2{{bypasses}}
1246 case 0: // expected-error {{cannot jump}}
1248 throw n;
1249 } catch (...) { // expected-note 2{{bypasses}}
1250 case 1: // expected-error {{cannot jump}}
1252 throw n;
1254 case 2:
1255 goto x; // expected-error {{cannot jump}}
1256 case 3:
1257 goto y; // expected-error {{cannot jump}}
1262 namespace dr99 { // dr99: sup 214
1263 template<typename T> void f(T&);
1264 template<typename T> int &f(const T&);
1265 const int n = 0;
1266 int &r = f(n);