dr0xx.cpp revision 576a9af150e4ddb34fd9cbede6eb5e3cf2bae9c8
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: 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
234namespace 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
240namespace 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
248namespace 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
268namespace 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
276namespace dr27 { // dr27: yes
277  enum E { e } n;
278  E &m = true ? n : n;
279}
280
281// dr28: na
282
283namespace dr29 { // dr29: no
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  // FIXME: We should reject this.
295  void g2() { void dr29_f2(); }
296  extern "C" void dr29_f2();
297
298  // FIXME: We should reject this.
299  extern "C" void g3() { void dr29_f3(); }
300  extern "C++" void dr29_f3();
301
302  // FIXME: We should reject this.
303  extern "C++" void g4() { void dr29_f4(); }
304  extern "C" void dr29_f4();
305
306  extern "C" void g5();
307  extern "C++" void dr29_f5();
308  void g5() {
309    void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
310  }
311
312  extern "C++" void g6();
313  extern "C" void dr29_f6();
314  void g6() {
315    void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
316  }
317
318  extern "C" void g7();
319  extern "C++" void dr29_f7(); // expected-note {{here}}
320  extern "C" void g7() {
321    void dr29_f7(); // expected-error {{different language linkage}}
322  }
323
324  extern "C++" void g8();
325  extern "C" void dr29_f8(); // expected-note {{here}}
326  extern "C++" void g8() {
327    void dr29_f8(); // expected-error {{different language linkage}}
328  }
329}
330
331namespace dr30 { // dr30: sup 468
332  struct A {
333    template<int> static int f();
334  } a, *p = &a;
335  int x = A::template f<0>();
336  int y = a.template f<0>();
337  int z = p->template f<0>();
338#if __cplusplus < 201103L
339  // FIXME: It's not clear whether DR468 applies to C++98 too.
340  // expected-error@-5 {{'template' keyword outside of a template}}
341  // expected-error@-5 {{'template' keyword outside of a template}}
342  // expected-error@-5 {{'template' keyword outside of a template}}
343#endif
344}
345
346namespace dr31 { // dr31: yes
347  class X {
348  private:
349    void operator delete(void*); // expected-note {{here}}
350  };
351  // We would call X::operator delete if X() threw (even though it can't,
352  // and even though we allocated the X using ::operator delete).
353  X *p = new X; // expected-error {{private}}
354}
355
356// dr32: na
357
358namespace dr33 { // dr33: yes
359  namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}}
360  namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}}
361  void g(X::S);
362  template<typename Z> Z g(Y::T);
363  void h() { f(&g); } // expected-error {{ambiguous}}
364}
365
366// dr34: na
367// dr35: dup 178
368// dr37: sup 475
369
370namespace dr38 { // dr38: yes
371  template<typename T> struct X {};
372  template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }
373  template X<int> operator+<int>(X<int>, X<int>);
374}
375
376namespace dr39 { // dr39: no
377  namespace example1 {
378    struct A { int &f(int); };
379    struct B : A {
380      using A::f;
381      float &f(float);
382    } b;
383    int &r = b.f(0);
384  }
385
386  namespace example2 {
387    struct A {
388      int &x(int); // expected-note {{found}}
389      static int &y(int); // expected-note {{found}}
390    };
391    struct V {
392      int &z(int);
393    };
394    struct B : A, virtual V {
395      using A::x; // expected-note {{found}}
396      float &x(float);
397      using A::y; // expected-note {{found}}
398      static float &y(float);
399      using V::z;
400      float &z(float);
401    };
402    struct C : A, B, virtual V {} c;
403    int &x = c.x(0); // expected-error {{found in multiple base classes}}
404    // FIXME: This is valid, because we find the same static data member either way.
405    int &y = c.y(0); // expected-error {{found in multiple base classes}}
406    int &z = c.z(0);
407  }
408
409  namespace example3 {
410    struct A { static int f(); };
411    struct B : virtual A { using A::f; };
412    struct C : virtual A { using A::f; };
413    struct D : B, C {} d;
414    int k = d.f();
415  }
416
417  namespace example4 {
418    struct A { int n; }; // expected-note {{found}}
419    struct B : A {};
420    struct C : A {};
421    struct D : B, C { int f() { return n; } }; // expected-error {{found in multiple base-class}}
422  }
423
424  namespace PR5916 {
425    // FIXME: This is valid.
426    struct A { int n; }; // expected-note +{{found}}
427    struct B : A {};
428    struct C : A {};
429    struct D : B, C {};
430    int k = sizeof(D::n); // expected-error {{found in multiple base}} expected-error {{unknown type name}}
431#if __cplusplus >= 201103L
432    decltype(D::n) n; // expected-error {{found in multiple base}}
433#endif
434  }
435}
436
437// dr40: na
438
439namespace dr41 { // dr41: yes
440  struct S f(S);
441}
442
443namespace dr42 { // dr42: yes
444  struct A { static const int k = 0; };
445  struct B : A { static const int k = A::k; };
446}
447
448// dr43: na
449
450namespace dr44 { // dr44: yes
451  struct A {
452    template<int> void f();
453    template<> void f<0>(); // expected-error {{explicit specialization of 'f' in class scope}}
454  };
455}
456
457namespace dr45 { // dr45: yes
458  class A {
459    class B {};
460    class C : B {};
461    C c;
462  };
463}
464
465namespace dr46 { // dr46: yes
466  template<typename> struct A { template<typename> struct B {}; };
467  template template struct A<int>::B<int>; // expected-error {{expected unqualified-id}}
468}
469
470namespace dr47 { // dr47: no
471  template<typename T> struct A {
472    friend void f() { T t; }
473  };
474  A<int> a;
475  A<float> b;
476#if __cplusplus < 201103L
477  // expected-error@-5 {{redefinition}} expected-note@-5 {{previous}}
478  // expected-note@-3 {{instantiation of}}
479#else
480  void f();
481  // FIXME: We should produce some kind of error here. C++11 [temp.friend]p4
482  // says we instantiate 'f' when it's odr-used, but that doesn't imply that
483  // this is valid; we still have multiple definitions of 'f' even if we never
484  // instantiate any of them.
485  void g() { f(); }
486#endif
487}
488
489namespace dr48 { // dr48: yes
490  namespace {
491    struct S {
492      static const int m = 0;
493      static const int n = 0;
494      static const int o = 0;
495    };
496  }
497  int a = S::m;
498  // FIXME: We should produce a 'has internal linkage but is not defined'
499  // diagnostic for 'S::n'.
500  const int &b = S::n;
501  const int S::o;
502  const int &c = S::o;
503}
504
505namespace dr49 { // dr49: yes
506  template<int*> struct A {}; // expected-note {{here}}
507  int k;
508#if __has_feature(cxx_constexpr)
509  constexpr
510#endif
511  int *const p = &k;
512  A<&k> a;
513  A<p> b; // expected-error {{must have its address taken}}
514#if __cplusplus < 201103L
515  // expected-error@-2 {{internal linkage}}
516  // expected-note@-5 {{here}}
517#endif
518}
519
520namespace dr50 { // dr50: yes
521  struct X; // expected-note {{forward}}
522  extern X *p;
523  X *q = (X*)p;
524  X *r = static_cast<X*>(p);
525  X *s = const_cast<X*>(p);
526  X *t = reinterpret_cast<X*>(p);
527  X *u = dynamic_cast<X*>(p); // expected-error {{incomplete}}
528}
529
530namespace dr51 { // dr51: yes
531  struct A {};
532  struct B : A {};
533  struct S {
534    operator A&();
535    operator B&();
536  } s;
537  A &a = s;
538}
539
540namespace dr52 { // dr52: yes
541  struct A { int n; }; // expected-note {{here}}
542  struct B : private A {} b; // expected-note 2{{private}}
543  // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
544  int k = b.A::n; // expected-error {{'A' is a private member of 'dr52::A'}}
545  // expected-error@-1 {{cannot cast 'struct B' to its private base}}
546}
547
548namespace dr53 { // dr53: yes
549  int n = 0;
550  enum E { e } x = static_cast<E>(n);
551}
552
553namespace dr54 { // dr54: yes
554  struct A { int a; } a;
555  struct V { int v; } v;
556  struct B : private A, virtual V { int b; } b; // expected-note 6{{private here}}
557
558  A &sab = static_cast<A&>(b); // expected-error {{private base}}
559  A *spab = static_cast<A*>(&b); // expected-error {{private base}}
560  int A::*smab = static_cast<int A::*>(&B::b); // expected-error {{private base}}
561  B &sba = static_cast<B&>(a); // expected-error {{private base}}
562  B *spba = static_cast<B*>(&a); // expected-error {{private base}}
563  int B::*smba = static_cast<int B::*>(&A::a); // expected-error {{private base}}
564
565  V &svb = static_cast<V&>(b);
566  V *spvb = static_cast<V*>(&b);
567  int V::*smvb = static_cast<int V::*>(&B::b); // expected-error {{virtual base}}
568  B &sbv = static_cast<B&>(v); // expected-error {{virtual base}}
569  B *spbv = static_cast<B*>(&v); // expected-error {{virtual base}}
570  int B::*smbv = static_cast<int B::*>(&V::v); // expected-error {{virtual base}}
571
572  A &cab = (A&)(b);
573  A *cpab = (A*)(&b);
574  int A::*cmab = (int A::*)(&B::b);
575  B &cba = (B&)(a);
576  B *cpba = (B*)(&a);
577  int B::*cmba = (int B::*)(&A::a);
578
579  V &cvb = (V&)(b);
580  V *cpvb = (V*)(&b);
581  int V::*cmvb = (int V::*)(&B::b); // expected-error {{virtual base}}
582  B &cbv = (B&)(v); // expected-error {{virtual base}}
583  B *cpbv = (B*)(&v); // expected-error {{virtual base}}
584  int B::*cmbv = (int B::*)(&V::v); // expected-error {{virtual base}}
585}
586
587namespace dr55 { // dr55: yes
588  enum E { e = 5 };
589  int test[(e + 1 == 6) ? 1 : -1];
590}
591
592namespace dr56 { // dr56: yes
593  struct A {
594    typedef int T; // expected-note {{previous}}
595    typedef int T; // expected-error {{redefinition}}
596  };
597  struct B {
598    struct X;
599    typedef X X; // expected-note {{previous}}
600    typedef X X; // expected-error {{redefinition}}
601  };
602}
603
604namespace dr58 { // dr58: yes
605  // FIXME: Ideally, we should have a CodeGen test for this.
606#if __cplusplus >= 201103L
607  enum E1 { E1_0 = 0, E1_1 = 1 };
608  enum E2 { E2_0 = 0, E2_m1 = -1 };
609  struct X { E1 e1 : 1; E2 e2 : 1; };
610  static_assert(X{E1_1, E2_m1}.e1 == 1, "");
611  static_assert(X{E1_1, E2_m1}.e2 == -1, "");
612#endif
613}
614
615namespace dr59 { // dr59: yes
616  template<typename T> struct convert_to { operator T() const; };
617  struct A {}; // expected-note 2{{volatile qualifier}}
618  struct B : A {}; // expected-note 2{{volatile qualifier}}
619#if __cplusplus >= 201103L // move constructors
620  // expected-note@-3 2{{volatile qualifier}}
621  // expected-note@-3 2{{volatile qualifier}}
622#endif
623
624  A a1 = convert_to<A>();
625  A a2 = convert_to<A&>();
626  A a3 = convert_to<const A>();
627  A a4 = convert_to<const volatile A>(); // expected-error {{no viable}}
628  A a5 = convert_to<const volatile A&>(); // expected-error {{no viable}}
629
630  B b1 = convert_to<B>();
631  B b2 = convert_to<B&>();
632  B b3 = convert_to<const B>();
633  B b4 = convert_to<const volatile B>(); // expected-error {{no viable}}
634  B b5 = convert_to<const volatile B&>(); // expected-error {{no viable}}
635
636  int n1 = convert_to<int>();
637  int n2 = convert_to<int&>();
638  int n3 = convert_to<const int>();
639  int n4 = convert_to<const volatile int>();
640  int n5 = convert_to<const volatile int&>();
641}
642
643namespace dr60 { // dr60: yes
644  void f(int &);
645  int &f(...);
646  const int k = 0;
647  int &n = f(k);
648}
649
650namespace dr61 { // dr61: yes
651  struct X {
652    static void f();
653  } x;
654  struct Y {
655    static void f();
656    static void f(int);
657  } y;
658  // This is (presumably) valid, because x.f does not refer to an overloaded
659  // function name.
660  void (*p)() = &x.f;
661  void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}}
662  void (*r)() = 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