dr0xx.cpp revision fc5335dd8ead65b7dc1dedd75ed32f9e74f229d0
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
5namespace 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
32namespace 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
39namespace 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
48namespace 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
62namespace dr7 { // dr7: no
63  class A { public: ~A(); };
64  class B : virtual private A {};
65  class C : public B {} c; // FIXME: should be rejected, ~A is inaccessible
66
67  class X { ~X(); }; // expected-note {{here}}
68  class Y : X { ~Y() {} }; // expected-error {{private destructor}}
69
70  namespace PR16370 { // This regressed the first time DR7 was fixed.
71    struct S1 { virtual ~S1(); };
72    struct S2 : S1 {};
73    struct S3 : S2 {};
74    struct S4 : virtual S2 {};
75    struct S5 : S3, S4 {
76      S5();
77      ~S5();
78    };
79    S5::S5() {}
80  }
81}
82
83namespace dr8 { // dr8: dup 45
84  class A {
85    struct U;
86    static const int k = 5;
87    void f();
88    template<typename, int, void (A::*)()> struct T;
89
90    T<U, k, &A::f> *g();
91  };
92  A::T<A::U, A::k, &A::f> *A::g() { return 0; }
93}
94
95namespace dr9 { // dr9: yes
96  struct B {
97  protected:
98    int m; // expected-note {{here}}
99    friend int R1();
100  };
101  struct N : protected B { // expected-note 2{{protected}}
102    friend int R2();
103  } n;
104  int R1() { return n.m; } // expected-error {{protected base class}} expected-error {{protected member}}
105  int R2() { return n.m; }
106}
107
108namespace dr10 { // dr10: dup 45
109  class A {
110    struct B {
111      A::B *p;
112    };
113  };
114}
115
116namespace dr11 { // dr11: yes
117  template<typename T> struct A : T {
118    using typename T::U;
119    U u;
120  };
121  template<typename T> struct B : T {
122    using T::V;
123    V v; // expected-error {{unknown type name}}
124  };
125  struct X { typedef int U; };
126  A<X> ax;
127}
128
129namespace dr12 { // dr12: sup 239
130  enum E { e };
131  E &f(E, E = e);
132  void g() {
133    int &f(int, E = e);
134    // Under DR12, these call two different functions.
135    // Under DR239, they call the same function.
136    int &b = f(e);
137    int &c = f(1);
138  }
139}
140
141namespace dr14 { // dr14: yes
142  namespace X { extern "C" int dr14_f(); }
143  namespace Y { extern "C" int dr14_f(); }
144  using namespace X;
145  using namespace Y;
146  int k = dr14_f();
147
148  class C {
149    int k;
150    friend int Y::dr14_f();
151  } c;
152  namespace Z {
153    extern "C" int dr14_f() { return c.k; }
154  }
155
156  namespace X { typedef int T; typedef int U; } // expected-note {{candidate}}
157  namespace Y { typedef int T; typedef long U; } // expected-note {{candidate}}
158  T t; // ok, same type both times
159  U u; // expected-error {{ambiguous}}
160}
161
162namespace dr15 { // dr15: yes
163  template<typename T> void f(int); // expected-note {{previous}}
164  template<typename T> void f(int = 0); // expected-error {{default arguments cannot be added}}
165}
166
167namespace dr16 { // dr16: yes
168  class A { // expected-note {{here}}
169    void f(); // expected-note {{here}}
170    friend class C;
171  };
172  class B : A {}; // expected-note 4{{here}}
173  class C : B {
174    void g() {
175      f(); // expected-error {{private member}} expected-error {{private base}}
176      A::f(); // expected-error {{private member}} expected-error {{private base}}
177    }
178  };
179}
180
181namespace dr17 { // dr17: yes
182  class A {
183    int n;
184    int f();
185    struct C;
186  };
187  struct B : A {} b;
188  int A::f() { return b.n; }
189  struct A::C : A {
190    int g() { return n; }
191  };
192}
193
194namespace dr18 { // dr18: yes
195  typedef void Void;
196  void f(Void); // expected-error {{empty parameter list defined with a typedef of 'void'}}
197}
198
199namespace dr19 { // dr19: yes
200  struct A {
201    int n; // expected-note {{here}}
202  };
203  struct B : protected A { // expected-note {{here}}
204  };
205  struct C : B {} c;
206  struct D : B {
207    int get1() { return c.n; } // expected-error {{protected member}}
208    int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here
209  };
210}
211
212namespace dr20 { // dr20: yes
213  class X {
214  public:
215    X();
216  private:
217    X(const X&); // expected-note {{here}}
218  };
219  X f();
220  X x = f(); // expected-error {{private}}
221}
222
223namespace dr21 { // dr21: no
224  template<typename T> struct A;
225  struct X {
226    // FIXME: We should reject these, per [temp.param]p9.
227    template<typename T = int> friend struct A;
228    template<typename T = int> friend struct B;
229  };
230}
231
232namespace dr22 { // dr22: sup 481
233  template<typename dr22_T = dr22_T> struct X; // expected-error {{unknown type name 'dr22_T'}}
234  typedef int T;
235  template<typename T = T> struct Y;
236}
237
238namespace dr23 { // dr23: yes
239  template<typename T> void f(T, T); // expected-note {{candidate}}
240  template<typename T> void f(T, int); // expected-note {{candidate}}
241  void g() { f(0, 0); } // expected-error {{ambiguous}}
242}
243
244// dr24: na
245
246namespace dr25 { // dr25: yes
247  struct A {
248    void f() throw(int);
249  };
250  void (A::*f)() throw (int);
251  void (A::*g)() throw () = f; // expected-error {{is not superset of source}}
252  void (A::*g2)() throw () = 0;
253  void (A::*h)() throw (int, char) = f;
254  void (A::*i)() throw () = &A::f; // expected-error {{is not superset of source}}
255  void (A::*i2)() throw () = 0;
256  void (A::*j)() throw (int, char) = &A::f;
257  void x() {
258    // FIXME: Don't produce the second error here.
259    g2 = f; // expected-error {{is not superset}} expected-error {{incompatible}}
260    h = f;
261    i2 = &A::f; // expected-error {{is not superset}} expected-error {{incompatible}}
262    j = &A::f;
263  }
264}
265
266namespace dr26 { // dr26: yes
267  struct A { A(A, const A & = A()); }; // expected-error {{must pass its first argument by reference}}
268  struct B {
269    B(); // expected-note {{candidate}}
270    B(const B &, B = B()); // expected-error {{no matching constructor}} expected-note {{candidate}} expected-note {{here}}
271  };
272}
273
274namespace dr27 { // dr27: yes
275  enum E { e } n;
276  E &m = true ? n : n;
277}
278
279// dr28: na
280
281namespace dr29 { // dr29: no
282  void dr29_f0(); // expected-note {{here}}
283  void g0() { void dr29_f0(); }
284  extern "C++" void g0_cxx() { void dr29_f0(); }
285  extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}}
286
287  extern "C" void dr29_f1(); // expected-note {{here}}
288  void g1() { void dr29_f1(); }
289  extern "C" void g1_c() { void dr29_f1(); }
290  extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}}
291
292  // FIXME: We should reject this.
293  void g2() { void dr29_f2(); }
294  extern "C" void dr29_f2();
295
296  // FIXME: We should reject this.
297  extern "C" void g3() { void dr29_f3(); }
298  extern "C++" void dr29_f3();
299
300  // FIXME: We should reject this.
301  extern "C++" void g4() { void dr29_f4(); }
302  extern "C" void dr29_f4();
303
304  extern "C" void g5();
305  extern "C++" void dr29_f5();
306  void g5() {
307    void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
308  }
309
310  extern "C++" void g6();
311  extern "C" void dr29_f6();
312  void g6() {
313    void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
314  }
315
316  extern "C" void g7();
317  extern "C++" void dr29_f7(); // expected-note {{here}}
318  extern "C" void g7() {
319    void dr29_f7(); // expected-error {{different language linkage}}
320  }
321
322  extern "C++" void g8();
323  extern "C" void dr29_f8(); // expected-note {{here}}
324  extern "C++" void g8() {
325    void dr29_f8(); // expected-error {{different language linkage}}
326  }
327}
328
329namespace dr30 { // dr30: sup 468
330  struct A {
331    template<int> static int f();
332  } a, *p = &a;
333  int x = A::template f<0>();
334  int y = a.template f<0>();
335  int z = p->template f<0>();
336#if __cplusplus < 201103L
337  // FIXME: It's not clear whether DR468 applies to C++98 too.
338  // expected-error@-5 {{'template' keyword outside of a template}}
339  // expected-error@-5 {{'template' keyword outside of a template}}
340  // expected-error@-5 {{'template' keyword outside of a template}}
341#endif
342}
343
344namespace dr31 { // dr31: yes
345  class X {
346  private:
347    void operator delete(void*); // expected-note {{here}}
348  };
349  // We would call X::operator delete if X() threw (even though it can't,
350  // and even though we allocated the X using ::operator delete).
351  X *p = new X; // expected-error {{private}}
352}
353
354// dr32: na
355
356namespace dr33 { // dr33: yes
357  namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}}
358  namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}}
359  void g(X::S);
360  template<typename Z> Z g(Y::T);
361  void h() { f(&g); } // expected-error {{ambiguous}}
362}
363
364// dr34: na
365// dr35: dup 178
366// dr37: sup 475
367
368namespace dr38 { // dr38: yes
369  template<typename T> struct X {};
370  template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }
371  template X<int> operator+<int>(X<int>, X<int>);
372}
373
374namespace dr39 { // dr39: no
375  namespace example1 {
376    struct A { int &f(int); };
377    struct B : A {
378      using A::f;
379      float &f(float);
380    } b;
381    int &r = b.f(0);
382  }
383
384  namespace example2 {
385    struct A {
386      int &x(int); // expected-note {{found}}
387      static int &y(int); // expected-note {{found}}
388    };
389    struct V {
390      int &z(int);
391    };
392    struct B : A, virtual V {
393      using A::x; // expected-note {{found}}
394      float &x(float);
395      using A::y; // expected-note {{found}}
396      static float &y(float);
397      using V::z;
398      float &z(float);
399    };
400    struct C : A, B, virtual V {} c;
401    int &x = c.x(0); // expected-error {{found in multiple base classes}}
402    // FIXME: This is valid, because we find the same static data member either way.
403    int &y = c.y(0); // expected-error {{found in multiple base classes}}
404    int &z = c.z(0);
405  }
406
407  namespace example3 {
408    struct A { static int f(); };
409    struct B : virtual A { using A::f; };
410    struct C : virtual A { using A::f; };
411    struct D : B, C {} d;
412    int k = d.f();
413  }
414
415  namespace example4 {
416    struct A { int n; }; // expected-note {{found}}
417    struct B : A {};
418    struct C : A {};
419    struct D : B, C { int f() { return n; } }; // expected-error {{found in multiple base-class}}
420  }
421
422  namespace PR5916 {
423    // FIXME: This is valid.
424    struct A { int n; }; // expected-note +{{found}}
425    struct B : A {};
426    struct C : A {};
427    struct D : B, C {};
428    int k = sizeof(D::n); // expected-error {{found in multiple base}} expected-error {{unknown type name}}
429#if __cplusplus >= 201103L
430    decltype(D::n) n; // expected-error {{found in multiple base}}
431#endif
432  }
433}
434
435// dr40: na
436
437namespace dr41 { // dr41: yes
438  struct S f(S);
439}
440
441namespace dr42 { // dr42: yes
442  struct A { static const int k = 0; };
443  struct B : A { static const int k = A::k; };
444}
445
446// dr43: na
447
448namespace dr44 { // dr44: yes
449  struct A {
450    template<int> void f();
451    template<> void f<0>(); // expected-error {{explicit specialization of 'f' in class scope}}
452  };
453}
454
455namespace dr45 { // dr45: yes
456  class A {
457    class B {};
458    class C : B {};
459    C c;
460  };
461}
462
463namespace dr46 { // dr46: yes
464  template<typename> struct A { template<typename> struct B {}; };
465  template template struct A<int>::B<int>; // expected-error {{expected unqualified-id}}
466}
467
468namespace dr47 { // dr47: no
469  template<typename T> struct A {
470    friend void f() { T t; }
471  };
472  A<int> a;
473  A<float> b;
474#if __cplusplus < 201103L
475  // expected-error@-5 {{redefinition}} expected-note@-5 {{previous}}
476  // expected-note@-3 {{instantiation of}}
477#else
478  void f();
479  // FIXME: We should produce some kind of error here. C++11 [temp.friend]p4
480  // says we instantiate 'f' when it's odr-used, but that doesn't imply that
481  // this is valid; we still have multiple definitions of 'f' even if we never
482  // instantiate any of them.
483  void g() { f(); }
484#endif
485}
486
487namespace dr48 { // dr48: yes
488  namespace {
489    struct S {
490      static const int m = 0;
491      static const int n = 0;
492      static const int o = 0;
493    };
494  }
495  int a = S::m;
496  // FIXME: We should produce a 'has internal linkage but is not defined'
497  // diagnostic for 'S::n'.
498  const int &b = S::n;
499  const int S::o;
500  const int &c = S::o;
501}
502
503namespace dr49 { // dr49: yes
504  template<int*> struct A {}; // expected-note {{here}}
505  int k;
506#if __has_feature(cxx_constexpr)
507  constexpr
508#endif
509  int *const p = &k;
510  A<&k> a;
511  A<p> b; // expected-error {{must have its address taken}}
512#if __cplusplus < 201103L
513  // expected-error@-2 {{internal linkage}}
514  // expected-note@-5 {{here}}
515#endif
516}
517
518namespace dr50 { // dr50: yes
519  struct X; // expected-note {{forward}}
520  extern X *p;
521  X *q = (X*)p;
522  X *r = static_cast<X*>(p);
523  X *s = const_cast<X*>(p);
524  X *t = reinterpret_cast<X*>(p);
525  X *u = dynamic_cast<X*>(p); // expected-error {{incomplete}}
526}
527
528namespace dr51 { // dr51: yes
529  struct A {};
530  struct B : A {};
531  struct S {
532    operator A&();
533    operator B&();
534  } s;
535  A &a = s;
536}
537
538namespace dr52 { // dr52: yes
539  struct A { int n; }; // expected-note {{here}}
540  struct B : private A {} b; // expected-note 2{{private}}
541  // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
542  int k = b.A::n; // expected-error {{'A' is a private member of 'dr52::A'}}
543  // expected-error@-1 {{cannot cast 'struct B' to its private base}}
544}
545
546namespace dr53 { // dr53: yes
547  int n = 0;
548  enum E { e } x = static_cast<E>(n);
549}
550
551namespace dr54 { // dr54: yes
552  struct A { int a; } a;
553  struct V { int v; } v;
554  struct B : private A, virtual V { int b; } b; // expected-note 6{{private here}}
555
556  A &sab = static_cast<A&>(b); // expected-error {{private base}}
557  A *spab = static_cast<A*>(&b); // expected-error {{private base}}
558  int A::*smab = static_cast<int A::*>(&B::b); // expected-error {{private base}}
559  B &sba = static_cast<B&>(a); // expected-error {{private base}}
560  B *spba = static_cast<B*>(&a); // expected-error {{private base}}
561  int B::*smba = static_cast<int B::*>(&A::a); // expected-error {{private base}}
562
563  V &svb = static_cast<V&>(b);
564  V *spvb = static_cast<V*>(&b);
565  int V::*smvb = static_cast<int V::*>(&B::b); // expected-error {{virtual base}}
566  B &sbv = static_cast<B&>(v); // expected-error {{virtual base}}
567  B *spbv = static_cast<B*>(&v); // expected-error {{virtual base}}
568  int B::*smbv = static_cast<int B::*>(&V::v); // expected-error {{virtual base}}
569
570  A &cab = (A&)(b);
571  A *cpab = (A*)(&b);
572  int A::*cmab = (int A::*)(&B::b);
573  B &cba = (B&)(a);
574  B *cpba = (B*)(&a);
575  int B::*cmba = (int B::*)(&A::a);
576
577  V &cvb = (V&)(b);
578  V *cpvb = (V*)(&b);
579  int V::*cmvb = (int V::*)(&B::b); // expected-error {{virtual base}}
580  B &cbv = (B&)(v); // expected-error {{virtual base}}
581  B *cpbv = (B*)(&v); // expected-error {{virtual base}}
582  int B::*cmbv = (int B::*)(&V::v); // expected-error {{virtual base}}
583}
584
585namespace dr55 { // dr55: yes
586  enum E { e = 5 };
587  int test[(e + 1 == 6) ? 1 : -1];
588}
589
590namespace dr56 { // dr56: yes
591  struct A {
592    typedef int T; // expected-note {{previous}}
593    typedef int T; // expected-error {{redefinition}}
594  };
595  struct B {
596    struct X;
597    typedef X X; // expected-note {{previous}}
598    typedef X X; // expected-error {{redefinition}}
599  };
600}
601
602namespace dr58 { // dr58: yes
603  // FIXME: Ideally, we should have a CodeGen test for this.
604#if __cplusplus >= 201103L
605  enum E1 { E1_0 = 0, E1_1 = 1 };
606  enum E2 { E2_0 = 0, E2_m1 = -1 };
607  struct X { E1 e1 : 1; E2 e2 : 1; };
608  static_assert(X{E1_1, E2_m1}.e1 == 1, "");
609  static_assert(X{E1_1, E2_m1}.e2 == -1, "");
610#endif
611}
612
613namespace dr59 { // dr59: yes
614  template<typename T> struct convert_to { operator T() const; };
615  struct A {}; // expected-note 2{{volatile qualifier}}
616  struct B : A {}; // expected-note 2{{volatile qualifier}}
617#if __cplusplus >= 201103L // move constructors
618  // expected-note@-3 2{{volatile qualifier}}
619  // expected-note@-3 2{{volatile qualifier}}
620#endif
621
622  A a1 = convert_to<A>();
623  A a2 = convert_to<A&>();
624  A a3 = convert_to<const A>();
625  A a4 = convert_to<const volatile A>(); // expected-error {{no viable}}
626  A a5 = convert_to<const volatile A&>(); // expected-error {{no viable}}
627
628  B b1 = convert_to<B>();
629  B b2 = convert_to<B&>();
630  B b3 = convert_to<const B>();
631  B b4 = convert_to<const volatile B>(); // expected-error {{no viable}}
632  B b5 = convert_to<const volatile B&>(); // expected-error {{no viable}}
633
634  int n1 = convert_to<int>();
635  int n2 = convert_to<int&>();
636  int n3 = convert_to<const int>();
637  int n4 = convert_to<const volatile int>();
638  int n5 = convert_to<const volatile int&>();
639}
640
641namespace dr60 { // dr60: yes
642  void f(int &);
643  int &f(...);
644  const int k = 0;
645  int &n = f(k);
646}
647
648namespace dr61 { // dr61: yes
649  struct X {
650    static void f();
651  } x;
652  struct Y {
653    static void f();
654    static void f(int);
655  } y;
656  // This is (presumably) valid, because x.f does not refer to an overloaded
657  // function name.
658  void (*p)() = &x.f;
659  void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}}
660}
661
662namespace 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
717namespace dr63 { // dr63: yes
718  template<typename T> struct S { typename T::error e; };
719  extern S<int> *p;
720  void *q = p;
721}
722
723namespace 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
733namespace 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
750namespace 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
775namespace 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
791namespace 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
802namespace 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
809namespace dr74 { // dr74: yes
810  enum E { k = 5 };
811  int (*p)[k] = new int[k][k];
812}
813
814namespace dr75 { // dr75: yes
815  struct S {
816    static int n = 0; // expected-error {{non-const}}
817  };
818}
819
820namespace dr76 { // dr76: yes
821  const volatile int n = 1;
822  int arr[n]; // expected-error +{{variable length array}}
823}
824
825namespace dr77 { // dr77: yes
826  struct A {
827    struct B {};
828    friend struct B;
829  };
830}
831
832namespace 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
840namespace 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
861namespace dr83 { // dr83: yes
862  int &f(const char*);
863  char &f(char *);
864  int &k = f("foo");
865}
866
867namespace 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
882namespace 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
912namespace 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
920namespace 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
932namespace 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
961namespace dr91 { // dr91: yes
962  union U { friend int f(U); };
963  int k = f(U());
964}
965
966// dr93: na
967
968namespace dr94 { // dr94: yes
969  struct A { static const int n = 5; };
970  int arr[A::n];
971}
972
973namespace 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
988namespace 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
1008namespace dr97 { // dr97: yes
1009  struct A {
1010    static const int a = false;
1011    static const int b = !a;
1012  };
1013}
1014
1015namespace 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
1035namespace 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