]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CXX/drs/dr0xx.cpp
Vendor import of clang trunk r290819:
[FreeBSD/FreeBSD.git] / test / CXX / drs / dr0xx.cpp
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++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
5
6 namespace dr1 { // dr1: no
7   namespace X { extern "C" void dr1_f(int a = 1); }
8   namespace Y { extern "C" void dr1_f(int a = 1); }
9   using X::dr1_f; using Y::dr1_f;
10   void g() {
11     dr1_f(0);
12     // FIXME: This should be rejected, due to the ambiguous default argument.
13     dr1_f();
14   }
15   namespace X {
16     using Y::dr1_f;
17     void h() {
18       dr1_f(0);
19       // FIXME: This should be rejected, due to the ambiguous default argument.
20       dr1_f();
21     }
22   }
23
24   namespace X {
25     void z(int);
26   }
27   void X::z(int = 1) {} // expected-note {{previous}}
28   namespace X {
29     void z(int = 1); // expected-error {{redefinition of default argument}}
30   }
31
32   void i(int = 1);
33   void j() {
34     void i(int = 1);
35     using dr1::i;
36     i(0);
37     // FIXME: This should be rejected, due to the ambiguous default argument.
38     i();
39   }
40   void k() {
41     using dr1::i;
42     void i(int = 1);
43     i(0);
44     // FIXME: This should be rejected, due to the ambiguous default argument.
45     i();
46   }
47 }
48
49 namespace dr3 { // dr3: yes
50   template<typename T> struct A {};
51   template<typename T> void f(T) { A<T> a; } // expected-note {{implicit instantiation}}
52   template void f(int);
53   template<> struct A<int> {}; // expected-error {{explicit specialization of 'dr3::A<int>' after instantiation}}
54 }
55
56 namespace dr4 { // dr4: yes
57   extern "C" {
58     static void dr4_f(int) {}
59     static void dr4_f(float) {}
60     void dr4_g(int) {} // expected-note {{previous}}
61     void dr4_g(float) {} // expected-error {{conflicting types}}
62   }
63 }
64
65 namespace dr5 { // dr5: yes
66   struct A {} a;
67   struct B {
68     B(const A&);
69     B(const B&);
70   };
71   const volatile B b = a;
72
73   struct C { C(C&); };
74   struct D : C {};
75   struct E { operator D&(); } e;
76   const C c = e;
77 }
78
79 namespace dr7 { // dr7: yes
80   class A { public: ~A(); };
81   class B : virtual private A {}; // expected-note 2 {{declared private here}}
82   class C : public B {} c; // expected-error 2 {{inherited virtual base class 'dr7::A' has private destructor}} \
83                            // expected-note {{implicit default constructor for 'dr7::C' first required here}} \
84                            // expected-note {{implicit destructor for 'dr7::C' first required here}}
85   class VeryDerivedC : public B, virtual public A {} vdc;
86
87   class X { ~X(); }; // expected-note {{here}}
88   class Y : X { ~Y() {} }; // expected-error {{private destructor}}
89
90   namespace PR16370 { // This regressed the first time DR7 was fixed.
91     struct S1 { virtual ~S1(); };
92     struct S2 : S1 {};
93     struct S3 : S2 {};
94     struct S4 : virtual S2 {};
95     struct S5 : S3, S4 {
96       S5();
97       ~S5();
98     };
99     S5::S5() {}
100   }
101 }
102
103 namespace dr8 { // dr8: dup 45
104   class A {
105     struct U;
106     static const int k = 5;
107     void f();
108     template<typename, int, void (A::*)()> struct T;
109
110     T<U, k, &A::f> *g();
111   };
112   A::T<A::U, A::k, &A::f> *A::g() { return 0; }
113 }
114
115 namespace dr9 { // dr9: yes
116   struct B {
117   protected:
118     int m; // expected-note {{here}}
119     friend int R1();
120   };
121   struct N : protected B { // expected-note 2{{protected}}
122     friend int R2();
123   } n;
124   int R1() { return n.m; } // expected-error {{protected base class}} expected-error {{protected member}}
125   int R2() { return n.m; }
126 }
127
128 namespace dr10 { // dr10: dup 45
129   class A {
130     struct B {
131       A::B *p;
132     };
133   };
134 }
135
136 namespace dr11 { // dr11: yes
137   template<typename T> struct A : T {
138     using typename T::U;
139     U u;
140   };
141   template<typename T> struct B : T {
142     using T::V;
143     V v; // expected-error {{unknown type name}}
144   };
145   struct X { typedef int U; };
146   A<X> ax;
147 }
148
149 namespace dr12 { // dr12: sup 239
150   enum E { e };
151   E &f(E, E = e);
152   void g() {
153     int &f(int, E = e);
154     // Under DR12, these call two different functions.
155     // Under DR239, they call the same function.
156     int &b = f(e);
157     int &c = f(1);
158   }
159 }
160
161 namespace dr13 { // dr13: no
162   extern "C" void f(int);
163   void g(char);
164
165   template<typename T> struct A {
166     A(void (*fp)(T));
167   };
168   template<typename T> int h(void (T));
169
170   A<int> a1(f); // FIXME: We should reject this.
171   A<char> a2(g);
172   int a3 = h(f); // FIXME: We should reject this.
173   int a4 = h(g);
174 }
175
176 namespace dr14 { // dr14: yes
177   namespace X { extern "C" int dr14_f(); }
178   namespace Y { extern "C" int dr14_f(); }
179   using namespace X;
180   using namespace Y;
181   int k = dr14_f();
182
183   class C {
184     int k;
185     friend int Y::dr14_f();
186   } c;
187   namespace Z {
188     extern "C" int dr14_f() { return c.k; }
189   }
190
191   namespace X { typedef int T; typedef int U; } // expected-note {{candidate}}
192   namespace Y { typedef int T; typedef long U; } // expected-note {{candidate}}
193   T t; // ok, same type both times
194   U u; // expected-error {{ambiguous}}
195 }
196
197 namespace dr15 { // dr15: yes
198   template<typename T> void f(int); // expected-note {{previous}}
199   template<typename T> void f(int = 0); // expected-error {{default arguments cannot be added}}
200 }
201
202 namespace dr16 { // dr16: yes
203   class A { // expected-note {{here}}
204     void f(); // expected-note {{here}}
205     friend class C;
206   };
207   class B : A {}; // expected-note 4{{here}}
208   class C : B {
209     void g() {
210       f(); // expected-error {{private member}} expected-error {{private base}}
211       A::f(); // expected-error {{private member}} expected-error {{private base}}
212     }
213   };
214 }
215
216 namespace dr17 { // dr17: yes
217   class A {
218     int n;
219     int f();
220     struct C;
221   };
222   struct B : A {} b;
223   int A::f() { return b.n; }
224   struct A::C : A {
225     int g() { return n; }
226   };
227 }
228
229 // dr18: sup 577
230
231 namespace dr19 { // dr19: yes
232   struct A {
233     int n; // expected-note {{here}}
234   };
235   struct B : protected A { // expected-note {{here}}
236   };
237   struct C : B {} c;
238   struct D : B {
239     int get1() { return c.n; } // expected-error {{protected member}}
240     int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here
241   };
242 }
243
244 namespace dr20 { // dr20: yes
245   class X {
246   public:
247     X();
248   private:
249     X(const X&); // expected-note {{here}}
250   };
251   X &f();
252   X x = f(); // expected-error {{private}}
253 }
254
255 namespace dr21 { // dr21: yes
256   template<typename T> struct A;
257   struct X {
258     template<typename T = int> friend struct A; // expected-error {{default template argument not permitted on a friend template}}
259     template<typename T = int> friend struct B; // expected-error {{default template argument not permitted on a friend template}}
260   };
261 }
262
263 namespace dr22 { // dr22: sup 481
264   template<typename dr22_T = dr22_T> struct X; // expected-error {{unknown type name 'dr22_T'}}
265   typedef int T;
266   template<typename T = T> struct Y;
267 }
268
269 namespace dr23 { // dr23: yes
270   template<typename T> void f(T, T); // expected-note {{candidate}}
271   template<typename T> void f(T, int); // expected-note {{candidate}}
272   void g() { f(0, 0); } // expected-error {{ambiguous}}
273 }
274
275 // dr24: na
276
277 namespace dr25 { // dr25: yes
278   struct A {
279     void f() throw(int); // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
280   };
281   void (A::*f)() throw (int); // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
282   void (A::*g)() throw () = f;
283 #if __cplusplus <= 201402L
284   // expected-error@-2 {{is not superset of source}}
285 #else
286   // expected-error@-4 {{different exception specifications}}
287 #endif
288   void (A::*g2)() throw () = 0;
289   void (A::*h)() throw (int, char) = f; // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
290   void (A::*i)() throw () = &A::f;
291 #if __cplusplus <= 201402L
292   // expected-error@-2 {{is not superset of source}}
293 #else
294   // expected-error@-4 {{different exception specifications}}
295 #endif
296   void (A::*i2)() throw () = 0;
297   void (A::*j)() throw (int, char) = &A::f; // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
298   void x() {
299     g2 = f;
300 #if __cplusplus <= 201402L
301   // expected-error@-2 {{is not superset of source}}
302 #else
303   // expected-error@-4 {{different exception specifications}}
304 #endif
305     h = f;
306     i2 = &A::f;
307 #if __cplusplus <= 201402L
308   // expected-error@-2 {{is not superset of source}}
309 #else
310   // expected-error@-4 {{different exception specifications}}
311 #endif
312     j = &A::f;
313   }
314 }
315
316 namespace dr26 { // dr26: yes
317   struct A { A(A, const A & = A()); }; // expected-error {{must pass its first argument by reference}}
318   struct B {
319     B(); // expected-note 0-1{{candidate}}
320     B(const B &, B = B());
321 #if __cplusplus <= 201402L
322     // expected-error@-2 {{no matching constructor}} expected-note@-2 {{candidate}} expected-note@-2 {{here}}
323 #endif
324   };
325   struct C {
326     static C &f();
327     C(const C &, C = f()); // expected-error {{no matching constructor}} expected-note {{candidate}} expected-note {{here}}
328   };
329 }
330
331 namespace dr27 { // dr27: yes
332   enum E { e } n;
333   E &m = true ? n : n;
334 }
335
336 // dr28: na lib
337
338 namespace dr29 { // dr29: 3.4
339   void dr29_f0(); // expected-note {{here}}
340   void g0() { void dr29_f0(); }
341   extern "C++" void g0_cxx() { void dr29_f0(); }
342   extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}}
343
344   extern "C" void dr29_f1(); // expected-note {{here}}
345   void g1() { void dr29_f1(); }
346   extern "C" void g1_c() { void dr29_f1(); }
347   extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}}
348
349   void g2() { void dr29_f2(); } // expected-note {{here}}
350   extern "C" void dr29_f2(); // expected-error {{different language linkage}}
351
352   extern "C" void g3() { void dr29_f3(); } // expected-note {{here}}
353   extern "C++" void dr29_f3(); // expected-error {{different language linkage}}
354
355   extern "C++" void g4() { void dr29_f4(); } // expected-note {{here}}
356   extern "C" void dr29_f4(); // expected-error {{different language linkage}}
357
358   extern "C" void g5();
359   extern "C++" void dr29_f5();
360   void g5() {
361     void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
362   }
363
364   extern "C++" void g6();
365   extern "C" void dr29_f6();
366   void g6() {
367     void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
368   }
369
370   extern "C" void g7();
371   extern "C++" void dr29_f7(); // expected-note {{here}}
372   extern "C" void g7() {
373     void dr29_f7(); // expected-error {{different language linkage}}
374   }
375
376   extern "C++" void g8();
377   extern "C" void dr29_f8(); // expected-note {{here}}
378   extern "C++" void g8() {
379     void dr29_f8(); // expected-error {{different language linkage}}
380   }
381 }
382
383 namespace dr30 { // dr30: sup 468 c++11
384   struct A {
385     template<int> static int f();
386   } a, *p = &a;
387   int x = A::template f<0>();
388   int y = a.template f<0>();
389   int z = p->template f<0>();
390 #if __cplusplus < 201103L
391   // FIXME: It's not clear whether DR468 applies to C++98 too.
392   // expected-error@-5 {{'template' keyword outside of a template}}
393   // expected-error@-5 {{'template' keyword outside of a template}}
394   // expected-error@-5 {{'template' keyword outside of a template}}
395 #endif
396 }
397
398 namespace dr31 { // dr31: yes
399   class X {
400   private:
401     void operator delete(void*); // expected-note {{here}}
402   };
403   // We would call X::operator delete if X() threw (even though it can't,
404   // and even though we allocated the X using ::operator delete).
405   X *p = new X; // expected-error {{private}}
406 }
407
408 // dr32: na
409
410 namespace dr33 { // dr33: yes
411   namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}}
412   namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}}
413   void g(X::S);
414   template<typename Z> Z g(Y::T);
415   void h() { f(&g); } // expected-error {{ambiguous}}
416 }
417
418 // dr34: na
419 // dr35: dup 178
420 // dr37: sup 475
421
422 namespace dr38 { // dr38: yes
423   template<typename T> struct X {};
424   template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }
425   template X<int> operator+<int>(X<int>, X<int>);
426 }
427
428 namespace dr39 { // dr39: no
429   namespace example1 {
430     struct A { int &f(int); };
431     struct B : A {
432       using A::f;
433       float &f(float);
434     } b;
435     int &r = b.f(0);
436   }
437
438   namespace example2 {
439     struct A {
440       int &x(int); // expected-note {{found}}
441       static int &y(int); // expected-note {{found}}
442     };
443     struct V {
444       int &z(int);
445     };
446     struct B : A, virtual V {
447       using A::x; // expected-note {{found}}
448       float &x(float);
449       using A::y; // expected-note {{found}}
450       static float &y(float);
451       using V::z;
452       float &z(float);
453     };
454     struct C : A, B, virtual V {} c; // expected-warning {{direct base 'dr39::example2::A' is inaccessible due to ambiguity:\n    struct dr39::example2::C -> struct dr39::example2::A\n    struct dr39::example2::C -> struct dr39::example2::B -> struct dr39::example2::A}}
455     int &x = c.x(0); // expected-error {{found in multiple base classes}}
456     // FIXME: This is valid, because we find the same static data member either way.
457     int &y = c.y(0); // expected-error {{found in multiple base classes}}
458     int &z = c.z(0);
459   }
460
461   namespace example3 {
462     struct A { static int f(); };
463     struct B : virtual A { using A::f; };
464     struct C : virtual A { using A::f; };
465     struct D : B, C {} d;
466     int k = d.f();
467   }
468
469   namespace example4 {
470     struct A { int n; }; // expected-note {{found}}
471     struct B : A {};
472     struct C : A {};
473     struct D : B, C { int f() { return n; } }; // expected-error {{found in multiple base-class}}
474   }
475
476   namespace PR5916 {
477     // FIXME: This is valid.
478     struct A { int n; }; // expected-note +{{found}}
479     struct B : A {};
480     struct C : A {};
481     struct D : B, C {};
482     int k = sizeof(D::n); // expected-error {{found in multiple base}} expected-error {{unknown type name}}
483 #if __cplusplus >= 201103L
484     decltype(D::n) n; // expected-error {{found in multiple base}}
485 #endif
486   }
487 }
488
489 // dr40: na
490
491 namespace dr41 { // dr41: yes
492   struct S f(S);
493 }
494
495 namespace dr42 { // dr42: yes
496   struct A { static const int k = 0; };
497   struct B : A { static const int k = A::k; };
498 }
499
500 // dr43: na
501
502 namespace dr44 { // dr44: yes
503   struct A {
504     template<int> void f();
505     template<> void f<0>(); // expected-error {{explicit specialization of 'f' in class scope}}
506   };
507 }
508
509 namespace dr45 { // dr45: yes
510   class A {
511     class B {};
512     class C : B {};
513     C c;
514   };
515 }
516
517 namespace dr46 { // dr46: yes
518   template<typename> struct A { template<typename> struct B {}; };
519   template template struct A<int>::B<int>; // expected-error {{expected unqualified-id}}
520 }
521
522 namespace dr47 { // dr47: sup 329
523   template<typename T> struct A {
524     friend void f() { T t; } // expected-error {{redefinition}} expected-note {{previous}}
525   };
526   A<int> a;
527   A<float> b; // expected-note {{instantiation of}}
528
529   void f();
530   void g() { f(); }
531 }
532
533 namespace dr48 { // dr48: yes
534   namespace {
535     struct S {
536       static const int m = 0;
537       static const int n = 0;
538       static const int o = 0;
539     };
540   }
541   int a = S::m;
542   // FIXME: We should produce a 'has internal linkage but is not defined'
543   // diagnostic for 'S::n'.
544   const int &b = S::n;
545   const int S::o;
546   const int &c = S::o;
547 }
548
549 namespace dr49 { // dr49: yes
550   template<int*> struct A {}; // expected-note 0-2{{here}}
551   int k;
552 #if __has_feature(cxx_constexpr)
553   constexpr
554 #endif
555   int *const p = &k; // expected-note 0-2{{here}}
556   A<&k> a;
557   A<p> b;
558 #if __cplusplus <= 201402L
559   // expected-error@-2 {{must have its address taken}}
560 #endif
561 #if __cplusplus < 201103L
562   // expected-error@-5 {{internal linkage}}
563 #endif
564   int *q = &k;
565   A<q> c;
566 #if __cplusplus < 201103L
567   // expected-error@-2 {{must have its address taken}}
568 #else
569   // expected-error@-4 {{constant expression}}
570   // expected-note@-5 {{read of non-constexpr}}
571   // expected-note@-7 {{declared here}}
572 #endif
573 }
574
575 namespace dr50 { // dr50: yes
576   struct X; // expected-note {{forward}}
577   extern X *p;
578   X *q = (X*)p;
579   X *r = static_cast<X*>(p);
580   X *s = const_cast<X*>(p);
581   X *t = reinterpret_cast<X*>(p);
582   X *u = dynamic_cast<X*>(p); // expected-error {{incomplete}}
583 }
584
585 namespace dr51 { // dr51: yes
586   struct A {};
587   struct B : A {};
588   struct S {
589     operator A&();
590     operator B&();
591   } s;
592   A &a = s;
593 }
594
595 namespace dr52 { // dr52: yes
596   struct A { int n; }; // expected-note {{here}}
597   struct B : private A {} b; // expected-note 2{{private}}
598   // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
599   int k = b.A::n; // expected-error {{'A' is a private member of 'dr52::A'}}
600   // expected-error@-1 {{cannot cast 'struct B' to its private base}}
601 }
602
603 namespace dr53 { // dr53: yes
604   int n = 0;
605   enum E { e } x = static_cast<E>(n);
606 }
607
608 namespace dr54 { // dr54: yes
609   struct A { int a; } a;
610   struct V { int v; } v;
611   struct B : private A, virtual V { int b; } b; // expected-note 6{{private here}}
612
613   A &sab = static_cast<A&>(b); // expected-error {{private base}}
614   A *spab = static_cast<A*>(&b); // expected-error {{private base}}
615   int A::*smab = static_cast<int A::*>(&B::b); // expected-error {{private base}}
616   B &sba = static_cast<B&>(a); // expected-error {{private base}}
617   B *spba = static_cast<B*>(&a); // expected-error {{private base}}
618   int B::*smba = static_cast<int B::*>(&A::a); // expected-error {{private base}}
619
620   V &svb = static_cast<V&>(b);
621   V *spvb = static_cast<V*>(&b);
622   int V::*smvb = static_cast<int V::*>(&B::b); // expected-error {{virtual base}}
623   B &sbv = static_cast<B&>(v); // expected-error {{virtual base}}
624   B *spbv = static_cast<B*>(&v); // expected-error {{virtual base}}
625   int B::*smbv = static_cast<int B::*>(&V::v); // expected-error {{virtual base}}
626
627   A &cab = (A&)(b);
628   A *cpab = (A*)(&b);
629   int A::*cmab = (int A::*)(&B::b);
630   B &cba = (B&)(a);
631   B *cpba = (B*)(&a);
632   int B::*cmba = (int B::*)(&A::a);
633
634   V &cvb = (V&)(b);
635   V *cpvb = (V*)(&b);
636   int V::*cmvb = (int V::*)(&B::b); // expected-error {{virtual base}}
637   B &cbv = (B&)(v); // expected-error {{virtual base}}
638   B *cpbv = (B*)(&v); // expected-error {{virtual base}}
639   int B::*cmbv = (int B::*)(&V::v); // expected-error {{virtual base}}
640 }
641
642 namespace dr55 { // dr55: yes
643   enum E { e = 5 };
644   int test[(e + 1 == 6) ? 1 : -1];
645 }
646
647 namespace dr56 { // dr56: yes
648   struct A {
649     typedef int T; // expected-note {{previous}}
650     typedef int T; // expected-error {{redefinition}}
651   };
652   struct B {
653     struct X;
654     typedef X X; // expected-note {{previous}}
655     typedef X X; // expected-error {{redefinition}}
656   };
657 }
658
659 namespace dr58 { // dr58: yes
660   // FIXME: Ideally, we should have a CodeGen test for this.
661 #if __cplusplus >= 201103L
662   enum E1 { E1_0 = 0, E1_1 = 1 };
663   enum E2 { E2_0 = 0, E2_m1 = -1 };
664   struct X { E1 e1 : 1; E2 e2 : 1; };
665   static_assert(X{E1_1, E2_m1}.e1 == 1, "");
666   static_assert(X{E1_1, E2_m1}.e2 == -1, "");
667 #endif
668 }
669
670 namespace dr59 { // dr59: yes
671   template<typename T> struct convert_to { operator T() const; };
672   struct A {}; // expected-note 5+{{candidate}}
673   struct B : A {}; // expected-note 0+{{candidate}}
674
675   A a1 = convert_to<A>();
676   A a2 = convert_to<A&>();
677   A a3 = convert_to<const A>();
678   A a4 = convert_to<const volatile A>();
679 #if __cplusplus <= 201402L
680   // expected-error@-2 {{no viable}}
681 #endif
682   A a5 = convert_to<const volatile A&>(); // expected-error {{no viable}}
683
684   B b1 = convert_to<B>();
685   B b2 = convert_to<B&>();
686   B b3 = convert_to<const B>();
687   B b4 = convert_to<const volatile B>();
688 #if __cplusplus <= 201402L
689   // expected-error@-2 {{no viable}}
690 #endif
691   B b5 = convert_to<const volatile B&>(); // expected-error {{no viable}}
692
693   A c1 = convert_to<B>();
694   A c2 = convert_to<B&>();
695   A c3 = convert_to<const B>();
696   A c4 = convert_to<const volatile B>(); // expected-error {{no viable}}
697   A c5 = convert_to<const volatile B&>(); // expected-error {{no viable}}
698
699   int n1 = convert_to<int>();
700   int n2 = convert_to<int&>();
701   int n3 = convert_to<const int>();
702   int n4 = convert_to<const volatile int>();
703   int n5 = convert_to<const volatile int&>();
704 }
705
706 namespace dr60 { // dr60: yes
707   void f(int &);
708   int &f(...);
709   const int k = 0;
710   int &n = f(k);
711 }
712
713 namespace dr61 { // dr61: yes
714   struct X {
715     static void f();
716   } x;
717   struct Y {
718     static void f();
719     static void f(int);
720   } y;
721   // This is (presumably) valid, because x.f does not refer to an overloaded
722   // function name.
723   void (*p)() = &x.f;
724   void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}}
725   void (*r)() = y.f; // expected-error {{cannot create a non-constant pointer to member function}}
726 }
727
728 namespace dr62 { // dr62: yes
729   struct A {
730     struct { int n; } b;
731   };
732   template<typename T> struct X {};
733   template<typename T> T get() { return get<T>(); }
734   template<typename T> int take(T) { return 0; }
735
736   X<A> x1;
737   A a = get<A>();
738
739   typedef struct { } *NoNameForLinkagePtr;
740 #if __cplusplus < 201103L
741   // expected-note@-2 5{{here}}
742 #endif
743   NoNameForLinkagePtr noNameForLinkagePtr;
744
745   struct Danger {
746     NoNameForLinkagePtr p;
747   };
748
749   X<NoNameForLinkagePtr> x2;
750   X<const NoNameForLinkagePtr> x3;
751   NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>();
752   NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>();
753   int n1 = take(noNameForLinkagePtr);
754 #if __cplusplus < 201103L
755   // expected-error@-6 {{uses unnamed type}}
756   // expected-error@-6 {{uses unnamed type}}
757   // expected-error@-6 {{uses unnamed type}}
758   // expected-error@-6 {{uses unnamed type}}
759   // expected-error@-6 {{uses unnamed type}}
760 #endif
761
762   X<Danger> x4;
763
764   void f() {
765     struct NoLinkage {};
766     X<NoLinkage> a;
767     X<const NoLinkage> b;
768     get<NoLinkage>();
769     get<const NoLinkage>();
770     X<void (*)(NoLinkage A::*)> c;
771     X<int NoLinkage::*> d;
772 #if __cplusplus < 201103L
773   // expected-error@-7 {{uses local type}}
774   // expected-error@-7 {{uses local type}}
775   // expected-error@-7 {{uses local type}}
776   // expected-error@-7 {{uses local type}}
777   // expected-error@-7 {{uses local type}}
778   // expected-error@-7 {{uses local type}}
779 #endif
780   }
781 }
782
783 namespace dr63 { // dr63: yes
784   template<typename T> struct S { typename T::error e; };
785   extern S<int> *p;
786   void *q = p;
787 }
788
789 namespace dr64 { // dr64: yes
790   template<class T> void f(T);
791   template<class T> void f(T*);
792   template<> void f(int*);
793   template<> void f<int>(int*);
794   template<> void f(int);
795 }
796
797 // dr65: na
798
799 namespace dr66 { // dr66: no
800   namespace X {
801     int f(int n); // expected-note 2{{candidate}}
802   }
803   using X::f;
804   namespace X {
805     int f(int n = 0);
806     int f(int, int);
807   }
808   // FIXME: The first two calls here should be accepted.
809   int a = f(); // expected-error {{no matching function}}
810   int b = f(1);
811   int c = f(1, 2); // expected-error {{no matching function}}
812 }
813
814 // dr67: na
815
816 namespace dr68 { // dr68: yes
817   template<typename T> struct X {};
818   struct ::dr68::X<int> x1;
819   struct ::dr68::template X<int> x2;
820 #if __cplusplus < 201103L
821   // expected-error@-2 {{'template' keyword outside of a template}}
822 #endif
823   struct Y {
824     friend struct X<int>;
825     friend struct ::dr68::X<char>;
826     friend struct ::dr68::template X<double>;
827 #if __cplusplus < 201103L
828   // expected-error@-2 {{'template' keyword outside of a template}}
829 #endif
830   };
831   template<typename>
832   struct Z {
833     friend struct ::dr68::template X<double>;
834     friend typename ::dr68::X<double>;
835 #if __cplusplus < 201103L
836   // expected-error@-2 {{C++11 extension}}
837 #endif
838   };
839 }
840
841 namespace dr69 { // dr69: yes
842   template<typename T> static void f() {}
843   // FIXME: Should we warn here?
844   inline void g() { f<int>(); }
845   // FIXME: This should be rejected, per [temp.explicit]p11.
846   extern template void f<char>();
847 #if __cplusplus < 201103L
848   // expected-error@-2 {{C++11 extension}}
849 #endif
850   template<void(*)()> struct Q {};
851   Q<&f<int> > q;
852 #if __cplusplus < 201103L
853   // expected-error@-2 {{internal linkage}} expected-note@-11 {{here}}
854 #endif
855 }
856
857 namespace dr70 { // dr70: yes
858   template<int> struct A {};
859   template<int I, int J> int f(int (&)[I + J], A<I>, A<J>);
860   int arr[7];
861   int k = f(arr, A<3>(), A<4>());
862 }
863
864 // dr71: na
865 // dr72: dup 69
866
867 #if __cplusplus >= 201103L
868 namespace dr73 { // dr73: no
869   // The resolution to dr73 is unworkable. Consider:
870   int a, b;
871   static_assert(&a + 1 != &b, ""); // expected-error {{not an integral constant expression}}
872 }
873 #endif
874
875 namespace dr74 { // dr74: yes
876   enum E { k = 5 };
877   int (*p)[k] = new int[k][k];
878 }
879
880 namespace dr75 { // dr75: yes
881   struct S {
882     static int n = 0; // expected-error {{non-const}}
883   };
884 }
885
886 namespace dr76 { // dr76: yes
887   const volatile int n = 1;
888   int arr[n]; // expected-error +{{variable length array}}
889 }
890
891 namespace dr77 { // dr77: yes
892   struct A {
893     struct B {};
894     friend struct B;
895   };
896 }
897
898 namespace dr78 { // dr78: sup ????
899   // Under DR78, this is valid, because 'k' has static storage duration, so is
900   // zero-initialized.
901   const int k; // expected-error {{default initialization of an object of const}}
902 }
903
904 // dr79: na
905
906 namespace dr80 { // dr80: yes
907   struct A {
908     int A;
909   };
910   struct B {
911     static int B; // expected-error {{same name as its class}}
912   };
913   struct C {
914     int C; // expected-note {{hidden by}}
915     // FIXME: These diagnostics aren't very good.
916     C(); // expected-error {{must use 'struct' tag to refer to}} expected-error {{expected member name}}
917   };
918   struct D {
919     D();
920     int D; // expected-error {{same name as its class}}
921   };
922 }
923
924 // dr81: na
925 // dr82: dup 48
926
927 namespace dr83 { // dr83: yes
928   int &f(const char*);
929   char &f(char *);
930   int &k = f("foo");
931 }
932
933 namespace dr84 { // dr84: yes
934   struct B;
935   struct A { operator B() const; };
936   struct C {};
937   struct B {
938     B(B&); // expected-note 0-1{{candidate}}
939     B(C); // expected-note 0-1{{no known conversion from 'dr84::B' to 'dr84::C'}}
940     operator C() const;
941   };
942   A a;
943   // Cannot use B(C) / operator C() pair to construct the B from the B temporary
944   // here. In C++1z, we initialize the B object directly using 'A::operator B()'.
945   B b = a;
946 #if __cplusplus <= 201402L
947   // expected-error@-2 {{no viable}}
948 #endif
949 }
950
951 namespace dr85 { // dr85: yes
952   struct A {
953     struct B;
954     struct B {}; // expected-note{{previous declaration is here}}
955     struct B; // expected-error{{class member cannot be redeclared}}
956
957     union U;
958     union U {}; // expected-note{{previous declaration is here}}
959     union U; // expected-error{{class member cannot be redeclared}}
960
961 #if __cplusplus >= 201103L
962     enum E1 : int;
963     enum E1 : int { e1 }; // expected-note{{previous declaration is here}}
964     enum E1 : int; // expected-error{{class member cannot be redeclared}}
965
966     enum class E2;
967     enum class E2 { e2 }; // expected-note{{previous declaration is here}}
968     enum class E2; // expected-error{{class member cannot be redeclared}}
969 #endif
970   };
971
972   template <typename T>
973   struct C {
974     struct B {}; // expected-note{{previous declaration is here}}
975     struct B; // expected-error{{class member cannot be redeclared}}
976   };
977 }
978
979 // dr86: dup 446
980
981 namespace dr87 { // dr87: no
982   // FIXME: Superseded by dr1975
983   template<typename T> struct X {};
984   // FIXME: This is invalid.
985   X<void() throw()> x;
986   // This is valid under dr87 but not under dr1975.
987   X<void(void() throw())> y;
988 }
989
990 namespace dr88 { // dr88: yes
991   template<typename T> struct S {
992     static const int a = 1; // expected-note {{previous}}
993     static const int b;
994   };
995   template<> const int S<int>::a = 4; // expected-error {{already has an initializer}}
996   template<> const int S<int>::b = 4;
997 }
998
999 // dr89: na
1000
1001 namespace dr90 { // dr90: yes
1002   struct A {
1003     template<typename T> friend void dr90_f(T);
1004   };
1005   struct B : A {
1006     template<typename T> friend void dr90_g(T);
1007     struct C {};
1008     union D {};
1009   };
1010   struct E : B {};
1011   struct F : B::C {};
1012
1013   void test() {
1014     dr90_f(A());
1015     dr90_f(B());
1016     dr90_f(B::C()); // expected-error {{undeclared identifier}}
1017     dr90_f(B::D()); // expected-error {{undeclared identifier}}
1018     dr90_f(E());
1019     dr90_f(F()); // expected-error {{undeclared identifier}}
1020
1021     dr90_g(A()); // expected-error {{undeclared identifier}}
1022     dr90_g(B());
1023     dr90_g(B::C());
1024     dr90_g(B::D());
1025     dr90_g(E());
1026     dr90_g(F()); // expected-error {{undeclared identifier}}
1027   }
1028 }
1029
1030 namespace dr91 { // dr91: yes
1031   union U { friend int f(U); };
1032   int k = f(U());
1033 }
1034
1035 namespace dr92 { // dr92: 4.0 c++17
1036   void f() throw(int, float); // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
1037   void (*p)() throw(int) = &f; // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
1038 #if __cplusplus <= 201402L
1039   // expected-error@-2 {{target exception specification is not superset of source}}
1040 #else
1041   // expected-warning@-4 {{target exception specification is not superset of source}}
1042 #endif
1043   void (*q)() throw(int); // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
1044   void (**pp)() throw() = &q;
1045 #if __cplusplus <= 201402L
1046   // expected-error@-2 {{exception specifications are not allowed}}
1047 #else
1048   // expected-error@-4 {{cannot initialize}}
1049 #endif
1050
1051   void g(void() throw()); // expected-note 0-2 {{no known conversion}} expected-warning 0-1{{mangled name of 'g' will change in C++17}}
1052   void h() throw() {
1053     g(f); // expected-error-re {{{{is not superset|no matching function}}}}
1054     g(q); // expected-error-re {{{{is not superset|no matching function}}}}
1055   }
1056
1057   // Prior to C++17, this is OK because the exception specification is not
1058   // considered in this context. In C++17, we *do* perform an implicit
1059   // conversion (which performs initialization), and the exception specification
1060   // is part of the type of the parameter, so this is invalid.
1061   template<void() throw()> struct X {};
1062   X<&f> xp;
1063 #if __cplusplus > 201402L
1064   // expected-error@-2 {{not implicitly convertible}}
1065 #endif
1066
1067   template<void() throw(int)> struct Y {}; // expected-error 0-1{{ISO C++1z does not allow}} expected-note 0-1{{use 'noexcept}}
1068   Y<&h> yp; // ok
1069 }
1070
1071 // dr93: na
1072
1073 namespace dr94 { // dr94: yes
1074   struct A { static const int n = 5; };
1075   int arr[A::n];
1076 }
1077
1078 namespace dr95 { // dr95: yes
1079   struct A;
1080   struct B;
1081   namespace N {
1082     class C {
1083       friend struct A;
1084       friend struct B;
1085       static void f(); // expected-note {{here}}
1086     };
1087     struct A *p; // dr95::A, not dr95::N::A.
1088   }
1089   A *q = N::p; // ok, same type
1090   struct B { void f() { N::C::f(); } }; // expected-error {{private}}
1091 }
1092
1093 namespace dr96 { // dr96: no
1094   struct A {
1095     void f(int);
1096     template<typename T> int f(T);
1097     template<typename T> struct S {};
1098   } a;
1099   template<template<typename> class X> struct B {};
1100
1101   template<typename T>
1102   void test() {
1103     int k1 = a.template f<int>(0);
1104     // FIXME: This is ill-formed, because 'f' is not a template-id and does not
1105     // name a class template.
1106     // FIXME: What about alias templates?
1107     int k2 = a.template f(1);
1108     A::template S<int> s;
1109     B<A::template S> b;
1110   }
1111 }
1112
1113 namespace dr97 { // dr97: yes
1114   struct A {
1115     static const int a = false;
1116     static const int b = !a;
1117   };
1118 }
1119
1120 namespace dr98 { // dr98: yes
1121   void test(int n) {
1122     switch (n) {
1123       try { // expected-note 2{{bypasses}}
1124         case 0: // expected-error {{cannot jump}}
1125         x:
1126           throw n;
1127       } catch (...) { // expected-note 2{{bypasses}}
1128         case 1: // expected-error {{cannot jump}}
1129         y:
1130           throw n;
1131       }
1132       case 2:
1133         goto x; // expected-error {{cannot jump}}
1134       case 3:
1135         goto y; // expected-error {{cannot jump}}
1136     }
1137   }
1138 }
1139
1140 namespace dr99 { // dr99: sup 214
1141   template<typename T> void f(T&);
1142   template<typename T> int &f(const T&);
1143   const int n = 0;
1144   int &r = f(n);
1145 }