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