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