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