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
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
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;
g()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;
h()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   }
z(int=1)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);
j()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   }
k()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 {};
f(T)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" {
dr4_f(int)58     static void dr4_f(int) {}
dr4_f(float)59     static void dr4_f(float) {}
dr4_g(int)60     void dr4_g(int) {} // expected-note {{previous}}
dr4_g(float)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}}
~Y()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     };
S5()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   };
g()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;
R1()124   int R1() { return n.m; } // expected-error {{protected base class}} expected-error {{protected member}}
R2()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);
g()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 {
dr14_f()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 {
g()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;
f()223   int A::f() { return b.n; }
224   struct A::C : A {
gdr17::A::C225     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 {
get1dr19::D239     int get1() { return c.n; } // expected-error {{protected member}}
get2dr19::D240     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}}
g()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);
280   };
281   void (A::*f)() throw (int);
282   void (A::*g)() throw () = f; // expected-error {{is not superset of source}}
283   void (A::*g2)() throw () = 0;
284   void (A::*h)() throw (int, char) = f;
285   void (A::*i)() throw () = &A::f; // expected-error {{is not superset of source}}
286   void (A::*i2)() throw () = 0;
287   void (A::*j)() throw (int, char) = &A::f;
x()288   void x() {
289     // FIXME: Don't produce the second error here.
290     g2 = f; // expected-error {{is not superset}} expected-error {{incompatible}}
291     h = f;
292     i2 = &A::f; // expected-error {{is not superset}} expected-error {{incompatible}}
293     j = &A::f;
294   }
295 }
296 
297 namespace dr26 { // dr26: yes
298   struct A { A(A, const A & = A()); }; // expected-error {{must pass its first argument by reference}}
299   struct B {
300     B(); // expected-note {{candidate}}
301     B(const B &, B = B()); // expected-error {{no matching constructor}} expected-note {{candidate}} expected-note {{here}}
302   };
303 }
304 
305 namespace dr27 { // dr27: yes
306   enum E { e } n;
307   E &m = true ? n : n;
308 }
309 
310 // dr28: na
311 
312 namespace dr29 { // dr29: 3.4
313   void dr29_f0(); // expected-note {{here}}
g0()314   void g0() { void dr29_f0(); }
g0_cxx()315   extern "C++" void g0_cxx() { void dr29_f0(); }
g0_c()316   extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}}
317 
318   extern "C" void dr29_f1(); // expected-note {{here}}
g1()319   void g1() { void dr29_f1(); }
g1_c()320   extern "C" void g1_c() { void dr29_f1(); }
g1_cxx()321   extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}}
322 
g2()323   void g2() { void dr29_f2(); } // expected-note {{here}}
324   extern "C" void dr29_f2(); // expected-error {{different language linkage}}
325 
g3()326   extern "C" void g3() { void dr29_f3(); } // expected-note {{here}}
327   extern "C++" void dr29_f3(); // expected-error {{different language linkage}}
328 
g4()329   extern "C++" void g4() { void dr29_f4(); } // expected-note {{here}}
330   extern "C" void dr29_f4(); // expected-error {{different language linkage}}
331 
332   extern "C" void g5();
333   extern "C++" void dr29_f5();
g5()334   void g5() {
335     void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
336   }
337 
338   extern "C++" void g6();
339   extern "C" void dr29_f6();
g6()340   void g6() {
341     void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
342   }
343 
344   extern "C" void g7();
345   extern "C++" void dr29_f7(); // expected-note {{here}}
g7()346   extern "C" void g7() {
347     void dr29_f7(); // expected-error {{different language linkage}}
348   }
349 
350   extern "C++" void g8();
351   extern "C" void dr29_f8(); // expected-note {{here}}
g8()352   extern "C++" void g8() {
353     void dr29_f8(); // expected-error {{different language linkage}}
354   }
355 }
356 
357 namespace dr30 { // dr30: sup 468 c++11
358   struct A {
359     template<int> static int f();
360   } a, *p = &a;
361   int x = A::template f<0>();
362   int y = a.template f<0>();
363   int z = p->template f<0>();
364 #if __cplusplus < 201103L
365   // FIXME: It's not clear whether DR468 applies to C++98 too.
366   // expected-error@-5 {{'template' keyword outside of a template}}
367   // expected-error@-5 {{'template' keyword outside of a template}}
368   // expected-error@-5 {{'template' keyword outside of a template}}
369 #endif
370 }
371 
372 namespace dr31 { // dr31: yes
373   class X {
374   private:
375     void operator delete(void*); // expected-note {{here}}
376   };
377   // We would call X::operator delete if X() threw (even though it can't,
378   // and even though we allocated the X using ::operator delete).
379   X *p = new X; // expected-error {{private}}
380 }
381 
382 // dr32: na
383 
384 namespace dr33 { // dr33: yes
385   namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}}
386   namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}}
387   void g(X::S);
388   template<typename Z> Z g(Y::T);
h()389   void h() { f(&g); } // expected-error {{ambiguous}}
390 }
391 
392 // dr34: na
393 // dr35: dup 178
394 // dr37: sup 475
395 
396 namespace dr38 { // dr38: yes
397   template<typename T> struct X {};
operator +(X<T> a,X<T> b)398   template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }
399   template X<int> operator+<int>(X<int>, X<int>);
400 }
401 
402 namespace dr39 { // dr39: no
403   namespace example1 {
404     struct A { int &f(int); };
405     struct B : A {
406       using A::f;
407       float &f(float);
408     } b;
409     int &r = b.f(0);
410   }
411 
412   namespace example2 {
413     struct A {
414       int &x(int); // expected-note {{found}}
415       static int &y(int); // expected-note {{found}}
416     };
417     struct V {
418       int &z(int);
419     };
420     struct B : A, virtual V {
421       using A::x; // expected-note {{found}}
422       float &x(float);
423       using A::y; // expected-note {{found}}
424       static float &y(float);
425       using V::z;
426       float &z(float);
427     };
428     struct C : A, B, virtual V {} c;
429     int &x = c.x(0); // expected-error {{found in multiple base classes}}
430     // FIXME: This is valid, because we find the same static data member either way.
431     int &y = c.y(0); // expected-error {{found in multiple base classes}}
432     int &z = c.z(0);
433   }
434 
435   namespace example3 {
436     struct A { static int f(); };
437     struct B : virtual A { using A::f; };
438     struct C : virtual A { using A::f; };
439     struct D : B, C {} d;
440     int k = d.f();
441   }
442 
443   namespace example4 {
444     struct A { int n; }; // expected-note {{found}}
445     struct B : A {};
446     struct C : A {};
fdr39::example4::D447     struct D : B, C { int f() { return n; } }; // expected-error {{found in multiple base-class}}
448   }
449 
450   namespace PR5916 {
451     // FIXME: This is valid.
452     struct A { int n; }; // expected-note +{{found}}
453     struct B : A {};
454     struct C : A {};
455     struct D : B, C {};
456     int k = sizeof(D::n); // expected-error {{found in multiple base}} expected-error {{unknown type name}}
457 #if __cplusplus >= 201103L
458     decltype(D::n) n; // expected-error {{found in multiple base}}
459 #endif
460   }
461 }
462 
463 // dr40: na
464 
465 namespace dr41 { // dr41: yes
466   struct S f(S);
467 }
468 
469 namespace dr42 { // dr42: yes
470   struct A { static const int k = 0; };
471   struct B : A { static const int k = A::k; };
472 }
473 
474 // dr43: na
475 
476 namespace dr44 { // dr44: yes
477   struct A {
478     template<int> void f();
479     template<> void f<0>(); // expected-error {{explicit specialization of 'f' in class scope}}
480   };
481 }
482 
483 namespace dr45 { // dr45: yes
484   class A {
485     class B {};
486     class C : B {};
487     C c;
488   };
489 }
490 
491 namespace dr46 { // dr46: yes
492   template<typename> struct A { template<typename> struct B {}; };
493   template template struct A<int>::B<int>; // expected-error {{expected unqualified-id}}
494 }
495 
496 namespace dr47 { // dr47: sup 329
497   template<typename T> struct A {
f()498     friend void f() { T t; } // expected-error {{redefinition}} expected-note {{previous}}
499   };
500   A<int> a;
501   A<float> b; // expected-note {{instantiation of}}
502 
503   void f();
g()504   void g() { f(); }
505 }
506 
507 namespace dr48 { // dr48: yes
508   namespace {
509     struct S {
510       static const int m = 0;
511       static const int n = 0;
512       static const int o = 0;
513     };
514   }
515   int a = S::m;
516   // FIXME: We should produce a 'has internal linkage but is not defined'
517   // diagnostic for 'S::n'.
518   const int &b = S::n;
519   const int S::o;
520   const int &c = S::o;
521 }
522 
523 namespace dr49 { // dr49: yes
524   template<int*> struct A {}; // expected-note 0-2{{here}}
525   int k;
526 #if __has_feature(cxx_constexpr)
527   constexpr
528 #endif
529   int *const p = &k; // expected-note 0-2{{here}}
530   A<&k> a;
531   A<p> b;
532 #if __cplusplus <= 201402L
533   // expected-error@-2 {{must have its address taken}}
534 #endif
535 #if __cplusplus < 201103L
536   // expected-error@-5 {{internal linkage}}
537 #endif
538   int *q = &k;
539   A<q> c;
540 #if __cplusplus < 201103L
541   // expected-error@-2 {{must have its address taken}}
542 #else
543   // expected-error@-4 {{constant expression}}
544   // expected-note@-5 {{read of non-constexpr}}
545   // expected-note@-7 {{declared here}}
546 #endif
547 }
548 
549 namespace dr50 { // dr50: yes
550   struct X; // expected-note {{forward}}
551   extern X *p;
552   X *q = (X*)p;
553   X *r = static_cast<X*>(p);
554   X *s = const_cast<X*>(p);
555   X *t = reinterpret_cast<X*>(p);
556   X *u = dynamic_cast<X*>(p); // expected-error {{incomplete}}
557 }
558 
559 namespace dr51 { // dr51: yes
560   struct A {};
561   struct B : A {};
562   struct S {
563     operator A&();
564     operator B&();
565   } s;
566   A &a = s;
567 }
568 
569 namespace dr52 { // dr52: yes
570   struct A { int n; }; // expected-note {{here}}
571   struct B : private A {} b; // expected-note 2{{private}}
572   // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
573   int k = b.A::n; // expected-error {{'A' is a private member of 'dr52::A'}}
574   // expected-error@-1 {{cannot cast 'struct B' to its private base}}
575 }
576 
577 namespace dr53 { // dr53: yes
578   int n = 0;
579   enum E { e } x = static_cast<E>(n);
580 }
581 
582 namespace dr54 { // dr54: yes
583   struct A { int a; } a;
584   struct V { int v; } v;
585   struct B : private A, virtual V { int b; } b; // expected-note 6{{private here}}
586 
587   A &sab = static_cast<A&>(b); // expected-error {{private base}}
588   A *spab = static_cast<A*>(&b); // expected-error {{private base}}
589   int A::*smab = static_cast<int A::*>(&B::b); // expected-error {{private base}}
590   B &sba = static_cast<B&>(a); // expected-error {{private base}}
591   B *spba = static_cast<B*>(&a); // expected-error {{private base}}
592   int B::*smba = static_cast<int B::*>(&A::a); // expected-error {{private base}}
593 
594   V &svb = static_cast<V&>(b);
595   V *spvb = static_cast<V*>(&b);
596   int V::*smvb = static_cast<int V::*>(&B::b); // expected-error {{virtual base}}
597   B &sbv = static_cast<B&>(v); // expected-error {{virtual base}}
598   B *spbv = static_cast<B*>(&v); // expected-error {{virtual base}}
599   int B::*smbv = static_cast<int B::*>(&V::v); // expected-error {{virtual base}}
600 
601   A &cab = (A&)(b);
602   A *cpab = (A*)(&b);
603   int A::*cmab = (int A::*)(&B::b);
604   B &cba = (B&)(a);
605   B *cpba = (B*)(&a);
606   int B::*cmba = (int B::*)(&A::a);
607 
608   V &cvb = (V&)(b);
609   V *cpvb = (V*)(&b);
610   int V::*cmvb = (int V::*)(&B::b); // expected-error {{virtual base}}
611   B &cbv = (B&)(v); // expected-error {{virtual base}}
612   B *cpbv = (B*)(&v); // expected-error {{virtual base}}
613   int B::*cmbv = (int B::*)(&V::v); // expected-error {{virtual base}}
614 }
615 
616 namespace dr55 { // dr55: yes
617   enum E { e = 5 };
618   int test[(e + 1 == 6) ? 1 : -1];
619 }
620 
621 namespace dr56 { // dr56: yes
622   struct A {
623     typedef int T; // expected-note {{previous}}
624     typedef int T; // expected-error {{redefinition}}
625   };
626   struct B {
627     struct X;
628     typedef X X; // expected-note {{previous}}
629     typedef X X; // expected-error {{redefinition}}
630   };
631 }
632 
633 namespace dr58 { // dr58: yes
634   // FIXME: Ideally, we should have a CodeGen test for this.
635 #if __cplusplus >= 201103L
636   enum E1 { E1_0 = 0, E1_1 = 1 };
637   enum E2 { E2_0 = 0, E2_m1 = -1 };
638   struct X { E1 e1 : 1; E2 e2 : 1; };
639   static_assert(X{E1_1, E2_m1}.e1 == 1, "");
640   static_assert(X{E1_1, E2_m1}.e2 == -1, "");
641 #endif
642 }
643 
644 namespace dr59 { // dr59: yes
645   template<typename T> struct convert_to { operator T() const; };
646   struct A {}; // expected-note 2{{volatile qualifier}}
647   struct B : A {}; // expected-note 2{{volatile qualifier}}
648 #if __cplusplus >= 201103L // move constructors
649   // expected-note@-3 2{{volatile qualifier}}
650   // expected-note@-3 2{{volatile qualifier}}
651 #endif
652 
653   A a1 = convert_to<A>();
654   A a2 = convert_to<A&>();
655   A a3 = convert_to<const A>();
656   A a4 = convert_to<const volatile A>(); // expected-error {{no viable}}
657   A a5 = convert_to<const volatile A&>(); // expected-error {{no viable}}
658 
659   B b1 = convert_to<B>();
660   B b2 = convert_to<B&>();
661   B b3 = convert_to<const B>();
662   B b4 = convert_to<const volatile B>(); // expected-error {{no viable}}
663   B b5 = convert_to<const volatile B&>(); // expected-error {{no viable}}
664 
665   int n1 = convert_to<int>();
666   int n2 = convert_to<int&>();
667   int n3 = convert_to<const int>();
668   int n4 = convert_to<const volatile int>();
669   int n5 = convert_to<const volatile int&>();
670 }
671 
672 namespace dr60 { // dr60: yes
673   void f(int &);
674   int &f(...);
675   const int k = 0;
676   int &n = f(k);
677 }
678 
679 namespace dr61 { // dr61: yes
680   struct X {
681     static void f();
682   } x;
683   struct Y {
684     static void f();
685     static void f(int);
686   } y;
687   // This is (presumably) valid, because x.f does not refer to an overloaded
688   // function name.
689   void (*p)() = &x.f;
690   void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}}
691   void (*r)() = y.f; // expected-error {{cannot create a non-constant pointer to member function}}
692 }
693 
694 namespace dr62 { // dr62: yes
695   struct A {
696     struct { int n; } b;
697   };
698   template<typename T> struct X {};
get()699   template<typename T> T get() { return get<T>(); }
take(T)700   template<typename T> int take(T) { return 0; }
701 
702   X<A> x1;
703   A a = get<A>();
704 
705   typedef struct { } *NoNameForLinkagePtr;
706 #if __cplusplus < 201103L
707   // expected-note@-2 5{{here}}
708 #endif
709   NoNameForLinkagePtr noNameForLinkagePtr;
710 
711   struct Danger {
712     NoNameForLinkagePtr p;
713   };
714 
715   X<NoNameForLinkagePtr> x2;
716   X<const NoNameForLinkagePtr> x3;
717   NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>();
718   NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>();
719   int n1 = take(noNameForLinkagePtr);
720 #if __cplusplus < 201103L
721   // expected-error@-6 {{uses unnamed type}}
722   // expected-error@-6 {{uses unnamed type}}
723   // expected-error@-6 {{uses unnamed type}}
724   // expected-error@-6 {{uses unnamed type}}
725   // expected-error@-6 {{uses unnamed type}}
726 #endif
727 
728   X<Danger> x4;
729 
f()730   void f() {
731     struct NoLinkage {};
732     X<NoLinkage> a;
733     X<const NoLinkage> b;
734     get<NoLinkage>();
735     get<const NoLinkage>();
736     X<void (*)(NoLinkage A::*)> c;
737     X<int NoLinkage::*> d;
738 #if __cplusplus < 201103L
739   // expected-error@-7 {{uses local type}}
740   // expected-error@-7 {{uses local type}}
741   // expected-error@-7 {{uses local type}}
742   // expected-error@-7 {{uses local type}}
743   // expected-error@-7 {{uses local type}}
744   // expected-error@-7 {{uses local type}}
745 #endif
746   }
747 }
748 
749 namespace dr63 { // dr63: yes
750   template<typename T> struct S { typename T::error e; };
751   extern S<int> *p;
752   void *q = p;
753 }
754 
755 namespace dr64 { // dr64: yes
756   template<class T> void f(T);
757   template<class T> void f(T*);
758   template<> void f(int*);
759   template<> void f<int>(int*);
760   template<> void f(int);
761 }
762 
763 // dr65: na
764 
765 namespace dr66 { // dr66: no
766   namespace X {
767     int f(int n); // expected-note 2{{candidate}}
768   }
769   using X::f;
770   namespace X {
771     int f(int n = 0);
772     int f(int, int);
773   }
774   // FIXME: The first two calls here should be accepted.
775   int a = f(); // expected-error {{no matching function}}
776   int b = f(1);
777   int c = f(1, 2); // expected-error {{no matching function}}
778 }
779 
780 // dr67: na
781 
782 namespace dr68 { // dr68: yes
783   template<typename T> struct X {};
784   struct ::dr68::X<int> x1;
785   struct ::dr68::template X<int> x2;
786 #if __cplusplus < 201103L
787   // expected-error@-2 {{'template' keyword outside of a template}}
788 #endif
789   struct Y {
790     friend struct X<int>;
791     friend struct ::dr68::X<char>;
792     friend struct ::dr68::template X<double>;
793 #if __cplusplus < 201103L
794   // expected-error@-2 {{'template' keyword outside of a template}}
795 #endif
796   };
797   template<typename>
798   struct Z {
799     friend struct ::dr68::template X<double>;
800     friend typename ::dr68::X<double>;
801 #if __cplusplus < 201103L
802   // expected-error@-2 {{C++11 extension}}
803 #endif
804   };
805 }
806 
807 namespace dr69 { // dr69: yes
f()808   template<typename T> static void f() {}
809   // FIXME: Should we warn here?
g()810   inline void g() { f<int>(); }
811   // FIXME: This should be rejected, per [temp.explicit]p11.
812   extern template void f<char>();
813 #if __cplusplus < 201103L
814   // expected-error@-2 {{C++11 extension}}
815 #endif
816   template<void(*)()> struct Q {};
817   Q<&f<int> > q;
818 #if __cplusplus < 201103L
819   // expected-error@-2 {{internal linkage}} expected-note@-11 {{here}}
820 #endif
821 }
822 
823 namespace dr70 { // dr70: yes
824   template<int> struct A {};
825   template<int I, int J> int f(int (&)[I + J], A<I>, A<J>);
826   int arr[7];
827   int k = f(arr, A<3>(), A<4>());
828 }
829 
830 // dr71: na
831 // dr72: dup 69
832 
833 #if __cplusplus >= 201103L
834 namespace dr73 { // dr73: no
835   // The resolution to dr73 is unworkable. Consider:
836   int a, b;
837   static_assert(&a + 1 != &b, ""); // expected-error {{not an integral constant expression}}
838 }
839 #endif
840 
841 namespace dr74 { // dr74: yes
842   enum E { k = 5 };
843   int (*p)[k] = new int[k][k];
844 }
845 
846 namespace dr75 { // dr75: yes
847   struct S {
848     static int n = 0; // expected-error {{non-const}}
849   };
850 }
851 
852 namespace dr76 { // dr76: yes
853   const volatile int n = 1;
854   int arr[n]; // expected-error +{{variable length array}}
855 }
856 
857 namespace dr77 { // dr77: yes
858   struct A {
859     struct B {};
860     friend struct B;
861   };
862 }
863 
864 namespace dr78 { // dr78: sup ????
865   // Under DR78, this is valid, because 'k' has static storage duration, so is
866   // zero-initialized.
867   const int k; // expected-error {{default initialization of an object of const}} expected-note{{add an explicit initializer to initialize 'k'}}
868 }
869 
870 // dr79: na
871 
872 namespace dr80 { // dr80: yes
873   struct A {
874     int A;
875   };
876   struct B {
877     static int B; // expected-error {{same name as its class}}
878   };
879   struct C {
880     int C; // expected-note {{hidden by}}
881     // FIXME: These diagnostics aren't very good.
882     C(); // expected-error {{must use 'struct' tag to refer to}} expected-error {{expected member name}}
883   };
884   struct D {
885     D();
886     int D; // expected-error {{same name as its class}}
887   };
888 }
889 
890 // dr81: na
891 // dr82: dup 48
892 
893 namespace dr83 { // dr83: yes
894   int &f(const char*);
895   char &f(char *);
896   int &k = f("foo");
897 }
898 
899 namespace dr84 { // dr84: yes
900   struct B;
901   struct A { operator B() const; };
902   struct C {};
903   struct B {
904     B(B&); // expected-note {{candidate}}
905     B(C);
906     operator C() const;
907   };
908   A a;
909   // Cannot use B(C) / operator C() pair to construct the B from the B temporary
910   // here.
911   B b = a; // expected-error {{no viable}}
912 }
913 
914 namespace dr85 { // dr85: yes
915   struct A {
916     struct B;
917     struct B {}; // expected-note{{previous declaration is here}}
918     struct B; // expected-error{{class member cannot be redeclared}}
919 
920     union U;
921     union U {}; // expected-note{{previous declaration is here}}
922     union U; // expected-error{{class member cannot be redeclared}}
923 
924 #if __cplusplus >= 201103L
925     enum E1 : int;
926     enum E1 : int { e1 }; // expected-note{{previous declaration is here}}
927     enum E1 : int; // expected-error{{class member cannot be redeclared}}
928 
929     enum class E2;
930     enum class E2 { e2 }; // expected-note{{previous declaration is here}}
931     enum class E2; // expected-error{{class member cannot be redeclared}}
932 #endif
933   };
934 
935   template <typename T>
936   struct C {
937     struct B {}; // expected-note{{previous declaration is here}}
938     struct B; // expected-error{{class member cannot be redeclared}}
939   };
940 }
941 
942 // dr86: dup 446
943 
944 namespace dr87 { // dr87: no
945   template<typename T> struct X {};
946   // FIXME: This is invalid.
947   X<void() throw()> x;
948   // ... but this is valid.
949   X<void(void() throw())> y;
950 }
951 
952 namespace dr88 { // dr88: yes
953   template<typename T> struct S {
954     static const int a = 1; // expected-note {{previous}}
955     static const int b;
956   };
957   template<> const int S<int>::a = 4; // expected-error {{already has an initializer}}
958   template<> const int S<int>::b = 4;
959 }
960 
961 // dr89: na
962 
963 namespace dr90 { // dr90: yes
964   struct A {
965     template<typename T> friend void dr90_f(T);
966   };
967   struct B : A {
968     template<typename T> friend void dr90_g(T);
969     struct C {};
970     union D {};
971   };
972   struct E : B {};
973   struct F : B::C {};
974 
test()975   void test() {
976     dr90_f(A());
977     dr90_f(B());
978     dr90_f(B::C()); // expected-error {{undeclared identifier}}
979     dr90_f(B::D()); // expected-error {{undeclared identifier}}
980     dr90_f(E());
981     dr90_f(F()); // expected-error {{undeclared identifier}}
982 
983     dr90_g(A()); // expected-error {{undeclared identifier}}
984     dr90_g(B());
985     dr90_g(B::C());
986     dr90_g(B::D());
987     dr90_g(E());
988     dr90_g(F()); // expected-error {{undeclared identifier}}
989   }
990 }
991 
992 namespace dr91 { // dr91: yes
993   union U { friend int f(U); };
994   int k = f(U());
995 }
996 
997 namespace dr92 { // dr92: yes
998   void f() throw(int, float);
999   void (*p)() throw(int) = &f; // expected-error {{target exception specification is not superset of source}}
1000   void (*q)() throw(int);
1001   void (**pp)() throw() = &q; // expected-error {{exception specifications are not allowed}}
1002 
1003   void g(void() throw());
h()1004   void h() {
1005     g(f); // expected-error {{is not superset}}
1006     g(q); // expected-error {{is not superset}}
1007   }
1008 
1009   // Prior to C++17, this is OK because the exception specification is not
1010   // considered in this context. In C++17, we *do* perform an implicit
1011   // conversion (which performs initialization), but we convert to the type of
1012   // the template parameter, which does not include the exception specification.
1013   template<void() throw()> struct X {};
1014   X<&f> xp; // ok
1015 }
1016 
1017 // dr93: na
1018 
1019 namespace dr94 { // dr94: yes
1020   struct A { static const int n = 5; };
1021   int arr[A::n];
1022 }
1023 
1024 namespace dr95 { // dr95: yes
1025   struct A;
1026   struct B;
1027   namespace N {
1028     class C {
1029       friend struct A;
1030       friend struct B;
1031       static void f(); // expected-note {{here}}
1032     };
1033     struct A *p; // dr95::A, not dr95::N::A.
1034   }
1035   A *q = N::p; // ok, same type
fdr95::B1036   struct B { void f() { N::C::f(); } }; // expected-error {{private}}
1037 }
1038 
1039 namespace dr96 { // dr96: no
1040   struct A {
1041     void f(int);
1042     template<typename T> int f(T);
1043     template<typename T> struct S {};
1044   } a;
1045   template<template<typename> class X> struct B {};
1046 
1047   template<typename T>
test()1048   void test() {
1049     int k1 = a.template f<int>(0);
1050     // FIXME: This is ill-formed, because 'f' is not a template-id and does not
1051     // name a class template.
1052     // FIXME: What about alias templates?
1053     int k2 = a.template f(1);
1054     A::template S<int> s;
1055     B<A::template S> b;
1056   }
1057 }
1058 
1059 namespace dr97 { // dr97: yes
1060   struct A {
1061     static const int a = false;
1062     static const int b = !a;
1063   };
1064 }
1065 
1066 namespace dr98 { // dr98: yes
test(int n)1067   void test(int n) {
1068     switch (n) {
1069       try { // expected-note 2{{bypasses}}
1070         case 0: // expected-error {{cannot jump}}
1071         x:
1072           throw n;
1073       } catch (...) { // expected-note 2{{bypasses}}
1074         case 1: // expected-error {{cannot jump}}
1075         y:
1076           throw n;
1077       }
1078       case 2:
1079         goto x; // expected-error {{cannot jump}}
1080       case 3:
1081         goto y; // expected-error {{cannot jump}}
1082     }
1083   }
1084 }
1085 
1086 namespace dr99 { // dr99: sup 214
1087   template<typename T> void f(T&);
1088   template<typename T> int &f(const T&);
1089   const int n = 0;
1090   int &r = f(n);
1091 }
1092