Clang Project

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