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