Home | History | Annotate | Download | only in drs
      1 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      2 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      3 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      4 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      5 
      6 // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
      7 __extension__ typedef __SIZE_TYPE__ size_t;
      8 
      9 namespace std { struct type_info; }
     10 
     11 namespace dr400 { // dr400: yes
     12   struct A { int a; struct a {}; }; // expected-note 2{{conflicting}} expected-note {{ambiguous}}
     13   struct B { int a; struct a {}; }; // expected-note 2{{target}} expected-note {{ambiguous}}
     14   struct C : A, B { using A::a; struct a b; };
     15   struct D : A, B { using A::a; using B::a; struct a b; }; // expected-error 2{{conflicts}}
     16   struct E : A, B { struct a b; }; // expected-error {{found in multiple base classes}}
     17 }
     18 
     19 namespace dr401 { // dr401: yes
     20   template<class T, class U = typename T::type> class A : public T {}; // expected-error {{protected}} expected-error 2{{private}}
     21 
     22   class B {
     23   protected:
     24     typedef int type; // expected-note {{protected}}
     25   };
     26 
     27   class C {
     28     typedef int type; // expected-note {{private}}
     29     friend class A<C>; // expected-note {{default argument}}
     30   };
     31 
     32   class D {
     33     typedef int type; // expected-note {{private}}
     34     friend class A<D, int>;
     35   };
     36 
     37   A<B> *b; // expected-note {{default argument}}
     38   // FIXME: We're missing the "in instantiation of" note for the default
     39   // argument here.
     40   A<D> *d;
     41 
     42   struct E {
     43     template<class T, class U = typename T::type> class A : public T {};
     44   };
     45   class F {
     46     typedef int type;
     47     friend class E;
     48   };
     49   E::A<F> eaf; // ok, default argument is in befriended context
     50 
     51   // FIXME: Why do we get different diagnostics in C++11 onwards here? We seem
     52   // to not treat the default template argument as a SFINAE context in C++98.
     53   template<class T, class U = typename T::type> void f(T) {}
     54   void g(B b) { f(b); }
     55 #if __cplusplus < 201103L
     56   // expected-error@-3 0-1{{extension}} expected-error@-3 {{protected}} expected-note@-3 {{instantiation}}
     57   // expected-note@-3 {{substituting}}
     58 #else
     59   // expected-error@-5 {{no matching}} expected-note@-6 {{protected}}
     60 #endif
     61 }
     62 
     63 namespace dr403 { // dr403: yes
     64   namespace A {
     65     struct S {};
     66     int f(void*);
     67   }
     68   template<typename T> struct X {};
     69   typedef struct X<A::S>::X XS;
     70   XS *p;
     71   int k = f(p); // ok, finds A::f, even though type XS is a typedef-name
     72                 // referring to an elaborated-type-specifier naming a
     73                 // injected-class-name, which is about as far from a
     74                 // template-id as we can make it.
     75 }
     76 
     77 // dr404: na
     78 // (NB: also sup 594)
     79 
     80 namespace dr406 { // dr406: yes
     81   typedef struct {
     82     static int n; // expected-error {{static data member 'n' not allowed in anonymous struct}}
     83   } A;
     84 }
     85 
     86 namespace dr407 { // dr407: 3.8
     87   struct S;
     88   typedef struct S S;
     89   void f() {
     90     struct S *p;
     91     {
     92       typedef struct S S; // expected-note {{here}}
     93       struct S *p; // expected-error {{refers to a typedef}}
     94     }
     95   }
     96   struct S {};
     97 
     98   namespace UsingDir {
     99     namespace A {
    100       struct S {}; // expected-note {{found}}
    101     }
    102     namespace B {
    103       typedef int S; // expected-note {{found}}
    104     }
    105     namespace C {
    106       using namespace A;
    107       using namespace B;
    108       struct S s; // expected-error {{ambiguous}}
    109     }
    110     namespace D {
    111       using A::S;
    112       typedef struct S S;
    113       struct S s;
    114     }
    115     namespace E {
    116       // The standard doesn't say whether this is valid. We interpret
    117       // DR407 as meaning "if lookup finds both a tag and a typedef with the
    118       // same type, then it's OK in an elaborated-type-specifier".
    119       typedef A::S S;
    120       using A::S;
    121       struct S s;
    122     }
    123     namespace F {
    124       typedef A::S S;
    125     }
    126     // The standard doesn't say what to do in these cases either.
    127     namespace G {
    128       using namespace A;
    129       using namespace F;
    130       struct S s;
    131     }
    132     namespace H {
    133       using namespace F;
    134       using namespace A;
    135       struct S s;
    136     }
    137   }
    138 }
    139 
    140 namespace dr408 { // dr408: 3.4
    141   template<int N> void g() { int arr[N != 1 ? 1 : -1]; }
    142   template<> void g<2>() { }
    143 
    144   template<typename T> struct S {
    145     static int i[];
    146     void f();
    147   };
    148   template<typename T> int S<T>::i[] = { 1 };
    149 
    150   template<typename T> void S<T>::f() {
    151     g<sizeof (i) / sizeof (int)>();
    152   }
    153   template<> int S<int>::i[] = { 1, 2 };
    154   template void S<int>::f(); // uses g<2>(), not g<1>().
    155 
    156 
    157   template<typename T> struct R {
    158     static int arr[];
    159     void f();
    160   };
    161   template<typename T> int R<T>::arr[1];
    162   template<typename T> void R<T>::f() {
    163     int arr[sizeof(arr) != sizeof(int) ? 1 : -1];
    164   }
    165   template<> int R<int>::arr[2];
    166   template void R<int>::f();
    167 }
    168 
    169 namespace dr409 { // dr409: yes
    170   template<typename T> struct A {
    171     typedef int B;
    172     B b1;
    173     A::B b2;
    174     A<T>::B b3;
    175     A<T*>::B b4; // expected-error {{missing 'typename'}}
    176   };
    177 }
    178 
    179 namespace dr410 { // dr410: no
    180   template<class T> void f(T);
    181   void g(int);
    182   namespace M {
    183     template<class T> void h(T);
    184     template<class T> void i(T);
    185     struct A {
    186       friend void f<>(int);
    187       friend void h<>(int);
    188       friend void g(int);
    189       template<class T> void i(T);
    190       friend void i<>(int);
    191     private:
    192       static void z(); // expected-note {{private}}
    193     };
    194 
    195     template<> void h(int) { A::z(); }
    196     // FIXME: This should be ill-formed. The member A::i<> is befriended,
    197     // not this function.
    198     template<> void i(int) { A::z(); }
    199   }
    200   template<> void f(int) { M::A::z(); }
    201   void g(int) { M::A::z(); } // expected-error {{private}}
    202 }
    203 
    204 // dr412 is in its own file.
    205 
    206 namespace dr413 { // dr413: yes
    207   struct S {
    208     int a;
    209     int : 17;
    210     int b;
    211   };
    212   S s = { 1, 2, 3 }; // expected-error {{excess elements}}
    213 
    214   struct E {};
    215   struct T { // expected-note {{here}}
    216     int a;
    217     E e;
    218     int b;
    219   };
    220   T t1 = { 1, {}, 2 };
    221   T t2 = { 1, 2 }; // expected-error {{aggregate with no elements requires explicit braces}}
    222 }
    223 
    224 namespace dr414 { // dr414: dup 305
    225   struct X {};
    226   void f() {
    227     X x;
    228     struct X {};
    229     x.~X();
    230   }
    231 }
    232 
    233 namespace dr415 { // dr415: yes
    234   template<typename T> void f(T, ...) { T::error; }
    235   void f(int, int);
    236   void g() { f(0, 0); } // ok
    237 }
    238 
    239 namespace dr416 { // dr416: yes
    240   extern struct A a;
    241   int &operator+(const A&, const A&);
    242   int &k = a + a;
    243   struct A { float &operator+(A&); };
    244   float &f = a + a;
    245 }
    246 
    247 namespace dr417 { // dr417: no
    248   struct A;
    249   struct dr417::A {}; // expected-warning {{extra qualification}}
    250   struct B { struct X; };
    251   struct C : B {};
    252   struct C::X {}; // expected-error {{no struct named 'X' in 'dr417::C'}}
    253   struct B::X { struct Y; };
    254   struct C::X::Y {}; // ok!
    255   namespace N {
    256     struct D;
    257     struct E;
    258     struct F;
    259     struct H;
    260   }
    261   // FIXME: This is ill-formed.
    262   using N::D;
    263   struct dr417::D {}; // expected-warning {{extra qualification}}
    264   using namespace N;
    265   struct dr417::E {}; // expected-warning {{extra qualification}} expected-error {{no struct named 'E'}}
    266   struct N::F {};
    267   struct G;
    268   using N::H;
    269   namespace M {
    270     struct dr417::G {}; // expected-error {{namespace 'M' does not enclose}}
    271     struct dr417::H {}; // expected-error {{namespace 'M' does not enclose}}
    272   }
    273 }
    274 
    275 namespace dr420 { // dr420: yes
    276   template<typename T> struct ptr {
    277     T *operator->() const;
    278     T &operator*() const;
    279   };
    280   template<typename T, typename P> void test(P p) {
    281     p->~T();
    282     p->T::~T();
    283     (*p).~T();
    284     (*p).T::~T();
    285   }
    286   struct X {};
    287   template void test<int>(int*);
    288   template void test<int>(ptr<int>);
    289   template void test<X>(X*);
    290   template void test<X>(ptr<X>);
    291 
    292   template<typename T>
    293   void test2(T p) {
    294     p->template Y<int>::~Y<int>();
    295     p->~Y<int>();
    296     // FIXME: This is ill-formed, but this diagnostic is terrible. We should
    297     // reject this in the parser.
    298     p->template ~Y<int>(); // expected-error 2{{no member named '~typename Y<int>'}}
    299   }
    300   template<typename T> struct Y {};
    301   template void test2(Y<int>*); // expected-note {{instantiation}}
    302   template void test2(ptr<Y<int> >); // expected-note {{instantiation}}
    303 
    304   void test3(int *p, ptr<int> q) {
    305     typedef int Int;
    306     p->~Int();
    307     q->~Int();
    308     p->Int::~Int();
    309     q->Int::~Int();
    310   }
    311 
    312 #if __cplusplus >= 201103L
    313   template<typename T> using id = T;
    314   struct A { template<typename T> using id = T; };
    315   void test4(int *p, ptr<int> q) {
    316     p->~id<int>();
    317     q->~id<int>();
    318     p->id<int>::~id<int>();
    319     q->id<int>::~id<int>();
    320     p->template id<int>::~id<int>(); // expected-error {{expected unqualified-id}}
    321     q->template id<int>::~id<int>(); // expected-error {{expected unqualified-id}}
    322     p->A::template id<int>::~id<int>();
    323     q->A::template id<int>::~id<int>();
    324   }
    325 #endif
    326 }
    327 
    328 namespace dr421 { // dr421: yes
    329   struct X { X(); int n; int &r; };
    330   int *p = &X().n; // expected-error {{taking the address of a temporary}}
    331   int *q = &X().r;
    332 }
    333 
    334 namespace dr422 { // dr422: yes
    335   template<typename T, typename U> void f() {
    336     typedef T type; // expected-note {{prev}}
    337     typedef U type; // expected-error {{redef}}
    338   }
    339   template void f<int, int>();
    340   template void f<int, char>(); // expected-note {{instantiation}}
    341 }
    342 
    343 namespace dr423 { // dr423: yes
    344   template<typename T> struct X { operator T&(); };
    345   void f(X<int> x) { x += 1; }
    346 }
    347 
    348 namespace dr424 { // dr424: yes
    349   struct A {
    350     typedef int N; // expected-note {{previous}}
    351     typedef int N; // expected-error {{redefinition}}
    352 
    353     struct X;
    354     typedef X X; // expected-note {{previous}}
    355     struct X {};
    356 
    357     struct X *p;
    358     struct A::X *q;
    359     X *r;
    360 
    361     typedef X X; // expected-error {{redefinition}}
    362   };
    363   struct B {
    364     typedef int N;
    365   };
    366   struct C : B {
    367     typedef int N; // expected-note {{previous}}
    368     typedef int N; // expected-error {{redefinition}}
    369   };
    370 }
    371 
    372 namespace dr425 { // dr425: yes
    373   struct A { template<typename T> operator T() const; } a;
    374   float f = 1.0f * a; // expected-error {{ambiguous}} expected-note 5+{{built-in candidate}}
    375 
    376   template<typename T> struct is_float;
    377   template<> struct is_float<float> { typedef void type; };
    378 
    379   struct B {
    380     template<typename T, typename U = typename is_float<T>::type> operator T() const; // expected-error 0-1{{extension}}
    381   } b;
    382   float g = 1.0f * b; // ok
    383 }
    384 
    385 namespace dr427 { // dr427: yes
    386   struct B {};
    387   struct D : public B {
    388     D(B &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
    389   };
    390 
    391   extern D d1;
    392   B &b = d1;
    393   const D &d2 = static_cast<const D&>(b);
    394   const D &d3 = (const D&)b;
    395   const D &d4(b); // expected-error {{deleted}}
    396 }
    397 
    398 namespace dr428 { // dr428: yes
    399   template<typename T> T make();
    400   extern struct X x; // expected-note 5{{forward declaration}}
    401   void f() {
    402     throw void(); // expected-error {{cannot throw}}
    403     throw make<void*>();
    404     throw make<const volatile void*>();
    405     throw x; // expected-error {{cannot throw}}
    406     throw make<X&>(); // expected-error {{cannot throw}}
    407     throw make<X*>(); // expected-error {{cannot throw}}
    408     throw make<const volatile X&>(); // expected-error {{cannot throw}}
    409     throw make<const volatile X*>(); // expected-error {{cannot throw}}
    410   }
    411 }
    412 
    413 namespace dr429 { // dr429: yes c++11
    414   // FIXME: This rule is obviously intended to apply to C++98 as well.
    415   struct A {
    416     static void *operator new(size_t, size_t);
    417     static void operator delete(void*, size_t);
    418   } *a = new (0) A;
    419 #if __cplusplus >= 201103L
    420   // expected-error@-2 {{'new' expression with placement arguments refers to non-placement 'operator delete'}}
    421   // expected-note@-4 {{here}}
    422 #endif
    423   struct B {
    424     static void *operator new(size_t, size_t);
    425     static void operator delete(void*);
    426     static void operator delete(void*, size_t);
    427   } *b = new (0) B; // ok, second delete is not a non-placement deallocation function
    428 }
    429 
    430 namespace dr430 { // dr430: yes c++11
    431   // resolved by n2239
    432   // FIXME: This should apply in C++98 too.
    433   void f(int n) {
    434     int a[] = { n++, n++, n++ };
    435 #if __cplusplus < 201103L
    436     // expected-warning@-2 {{multiple unsequenced modifications to 'n'}}
    437 #endif
    438   }
    439 }
    440 
    441 namespace dr431 { // dr431: yes
    442   struct A {
    443     template<typename T> T *get();
    444     template<typename T> struct B {
    445       template<typename U> U *get();
    446     };
    447   };
    448 
    449   template<typename T> void f(A a) {
    450     a.get<A>()->get<T>();
    451     a.get<T>()
    452         ->get<T>(); // expected-error {{use 'template'}}
    453     a.get<T>()->template get<T>();
    454     a.A::get<T>();
    455     A::B<int> *b = a.get<A::B<int> >();
    456     b->get<int>();
    457     b->A::B<int>::get<int>();
    458     b->A::B<int>::get<T>();
    459     b->A::B<T>::get<int>(); // expected-error {{use 'template'}}
    460     b->A::B<T>::template get<int>();
    461     b->A::B<T>::get<T>(); // expected-error {{use 'template'}}
    462     b->A::B<T>::template get<T>();
    463     A::B<T> *c = a.get<A::B<T> >();
    464     c->get<int>(); // expected-error {{use 'template'}}
    465     c->template get<int>();
    466   }
    467 }
    468 
    469 namespace dr432 { // dr432: yes
    470   template<typename T> struct A {};
    471   template<typename T> struct B : A<B> {}; // expected-error {{requires template arguments}} expected-note {{declared}}
    472   template<typename T> struct C : A<C<T> > {};
    473 #if __cplusplus >= 201103L
    474   template<typename T> struct D : decltype(A<D>()) {}; // expected-error {{requires template arguments}} expected-note {{declared}}
    475 #endif
    476 }
    477 
    478 namespace dr433 { // dr433: yes
    479   template<class T> struct S {
    480     void f(union U*);
    481   };
    482   U *p;
    483   template<class T> void S<T>::f(union U*) {}
    484 
    485   S<int> s;
    486 }
    487 
    488 namespace dr434 { // dr434: yes
    489   void f() {
    490     const int ci = 0;
    491     int *pi = 0;
    492     const int *&rpci = pi; // expected-error {{cannot bind}}
    493     rpci = &ci;
    494     *pi = 1;
    495   }
    496 }
    497 
    498 // dr435: na
    499 
    500 namespace dr436 { // dr436: yes
    501   enum E { f }; // expected-note {{previous}}
    502   void f(); // expected-error {{redefinition}}
    503 }
    504 
    505 namespace dr437 { // dr437: sup 1308
    506   // This is superseded by 1308, which is in turn superseded by 1330,
    507   // which restores this rule.
    508   template<typename U> struct T : U {};
    509   struct S {
    510     void f() throw(S);
    511     void g() throw(T<S>);
    512     struct U;
    513     void h() throw(U);
    514     struct U {};
    515   };
    516 }
    517 
    518 // dr438 FIXME write a codegen test
    519 // dr439 FIXME write a codegen test
    520 // dr441 FIXME write a codegen test
    521 // dr442: sup 348
    522 // dr443: na
    523 
    524 namespace dr444 { // dr444: yes
    525   struct D;
    526   struct B { // expected-note {{candidate is the implicit copy}} expected-note 0-1 {{implicit move}}
    527     D &operator=(D &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
    528   };
    529   struct D : B { // expected-note {{candidate is the implicit}} expected-note 0-1 {{implicit move}}
    530     using B::operator=;
    531   } extern d;
    532   void f() {
    533     d = d; // expected-error {{deleted}}
    534   }
    535 }
    536 
    537 namespace dr445 { // dr445: yes
    538   class A { void f(); }; // expected-note {{private}}
    539   struct B {
    540     friend void A::f(); // expected-error {{private}}
    541   };
    542 }
    543 
    544 namespace dr446 { // dr446: yes
    545   struct C;
    546   struct A {
    547     A();
    548     A(const A&) = delete; // expected-error 0-1{{extension}} expected-note +{{deleted}}
    549     A(const C&);
    550   };
    551   struct C : A {};
    552   void f(A a, bool b, C c) {
    553     void(b ? a : a);
    554     b ? A() : a; // expected-error {{deleted}}
    555     b ? a : A(); // expected-error {{deleted}}
    556     b ? A() : A(); // expected-error {{deleted}}
    557 
    558     void(b ? a : c);
    559     b ? a : C(); // expected-error {{deleted}}
    560     b ? c : A(); // expected-error {{deleted}}
    561     b ? A() : C(); // expected-error {{deleted}}
    562   }
    563 }
    564 
    565 namespace dr447 { // dr447: yes
    566   struct A { int n; int a[4]; };
    567   template<int> struct U {
    568     typedef int type;
    569     template<typename V> static void h();
    570   };
    571   template<typename T> U<sizeof(T)> g(T);
    572   template<typename T, int N> void f(int n) {
    573     // ok, not type dependent
    574     g(__builtin_offsetof(A, n)).h<int>();
    575     g(__builtin_offsetof(T, n)).h<int>();
    576     // value dependent if first argument is a dependent type
    577     U<__builtin_offsetof(A, n)>::type a;
    578     U<__builtin_offsetof(T, n)>::type b; // expected-error +{{}} expected-warning 0+{{}}
    579     // as an extension, we allow the member-designator to include array indices
    580     g(__builtin_offsetof(A, a[0])).h<int>(); // expected-error {{extension}}
    581     g(__builtin_offsetof(A, a[N])).h<int>(); // expected-error {{extension}}
    582     U<__builtin_offsetof(A, a[0])>::type c; // expected-error {{extension}}
    583     U<__builtin_offsetof(A, a[N])>::type d; // expected-error {{extension}} expected-error +{{}} expected-warning 0+{{}}
    584   }
    585 }
    586 
    587 namespace dr448 { // dr448: yes
    588   template<typename T = int> void f(int); // expected-error 0-1{{extension}} expected-note {{no known conversion}}
    589   template<typename T> void g(T t) {
    590     f<T>(t); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
    591     dr448::f(t); // expected-error {{no matching function}}
    592   }
    593   template<typename T> void f(T); // expected-note {{should be declared prior to the call site}}
    594   namespace HideFromADL { struct X {}; }
    595   template void g(int); // ok
    596   template void g(HideFromADL::X); // expected-note {{instantiation of}}
    597 }
    598 
    599 // dr449: na
    600 
    601 namespace dr450 { // dr450: yes
    602   typedef int A[3];
    603   void f1(const A &);
    604   void f2(A &); // expected-note +{{not viable}}
    605   struct S { A n; };
    606   void g() {
    607     f1(S().n);
    608     f2(S().n); // expected-error {{no match}}}
    609   }
    610 #if __cplusplus >= 201103L
    611   void h() {
    612     f1(A{});
    613     f2(A{}); // expected-error {{no match}}
    614   }
    615 #endif
    616 }
    617 
    618 namespace dr451 { // dr451: yes
    619   const int a = 1 / 0; // expected-warning {{undefined}}
    620   const int b = 1 / 0; // expected-warning {{undefined}}
    621   int arr[b]; // expected-error +{{variable length arr}}
    622 }
    623 
    624 namespace dr452 { // dr452: yes
    625   struct A {
    626     int a, b, c;
    627     A *p;
    628     int f();
    629     A() : a(f()), b(this->f() + a), c(this->a), p(this) {}
    630   };
    631 }
    632 
    633 // dr454 FIXME write a codegen test
    634 
    635 namespace dr456 { // dr456: yes
    636   // sup 903 c++11
    637   const int null = 0;
    638   void *p = null;
    639 #if __cplusplus >= 201103L
    640   // expected-error@-2 {{cannot initialize}}
    641 #else
    642   // expected-warning@-4 {{null}}
    643 #endif
    644 
    645   const bool f = false;
    646   void *q = f;
    647 #if __cplusplus >= 201103L
    648   // expected-error@-2 {{cannot initialize}}
    649 #else
    650   // expected-warning@-4 {{null}}
    651 #endif
    652 }
    653 
    654 namespace dr457 { // dr457: yes
    655   const int a = 1;
    656   const volatile int b = 1;
    657   int ax[a];
    658   int bx[b]; // expected-error +{{variable length array}}
    659 
    660   enum E {
    661     ea = a,
    662     eb = b // expected-error {{constant}} expected-note {{read of volatile-qualified}}
    663   };
    664 }
    665 
    666 namespace dr458 { // dr458: no
    667   struct A {
    668     int T;
    669     int f();
    670     template<typename> int g();
    671   };
    672 
    673   template<typename> struct B : A {
    674     int f();
    675     template<typename> int g();
    676     template<typename> int h();
    677   };
    678 
    679   int A::f() {
    680     return T;
    681   }
    682   template<typename T>
    683   int A::g() {
    684     return T; // FIXME: this is invalid, it finds the template parameter
    685   }
    686 
    687   template<typename T>
    688   int B<T>::f() {
    689     return T;
    690   }
    691   template<typename T> template<typename U>
    692   int B<T>::g() {
    693     return T;
    694   }
    695   template<typename U> template<typename T>
    696   int B<U>::h() {
    697     return T; // FIXME: this is invalid, it finds the template parameter
    698   }
    699 }
    700 
    701 namespace dr460 { // dr460: yes
    702   namespace X { namespace Q { int n; } }
    703   namespace Y {
    704     using X; // expected-error {{requires a qualified name}}
    705     using dr460::X; // expected-error {{cannot refer to namespace}}
    706     using X::Q; // expected-error {{cannot refer to namespace}}
    707   }
    708 }
    709 
    710 // dr461: na
    711 // dr462 FIXME write a codegen test
    712 // dr463: na
    713 // dr464: na
    714 // dr465: na
    715 
    716 namespace dr466 { // dr466: no
    717   typedef int I;
    718   typedef const int CI;
    719   typedef volatile int VI;
    720   void f(int *a, CI *b, VI *c) {
    721     a->~I();
    722     a->~CI();
    723     a->~VI();
    724     a->I::~I();
    725     a->CI::~CI();
    726     a->VI::~VI();
    727 
    728     a->CI::~VI(); // FIXME: This is invalid; CI and VI are not the same scalar type.
    729 
    730     b->~I();
    731     b->~CI();
    732     b->~VI();
    733     b->I::~I();
    734     b->CI::~CI();
    735     b->VI::~VI();
    736 
    737     c->~I();
    738     c->~CI();
    739     c->~VI();
    740     c->I::~I();
    741     c->CI::~CI();
    742     c->VI::~VI();
    743   }
    744 }
    745 
    746 namespace dr467 { // dr467: yes
    747   int stuff();
    748 
    749   int f() {
    750     static bool done;
    751     if (done)
    752       goto later;
    753     static int k = stuff();
    754     done = true;
    755   later:
    756     return k;
    757   }
    758   int g() {
    759     goto later; // expected-error {{cannot jump}}
    760     int k = stuff(); // expected-note {{bypasses variable initialization}}
    761   later:
    762     return k;
    763   }
    764 }
    765 
    766 namespace dr468 { // dr468: yes c++11
    767   // FIXME: Should we allow this in C++98 too?
    768   template<typename> struct A {
    769     template<typename> struct B {
    770       static int C;
    771     };
    772   };
    773   int k = dr468::template A<int>::template B<char>::C;
    774 #if __cplusplus < 201103L
    775   // expected-error@-2 2{{'template' keyword outside of a template}}
    776 #endif
    777 }
    778 
    779 namespace dr469 { // dr469: no
    780   // FIXME: The core issue here didn't really answer the question. We don't
    781   // deduce 'const T' from a function or reference type in a class template...
    782   template<typename T> struct X; // expected-note 2{{here}}
    783   template<typename T> struct X<const T> {};
    784   X<int&> x; // expected-error {{undefined}}
    785   X<int()> y; // expected-error {{undefined}}
    786 
    787   // ... but we do in a function template. GCC and EDG fail deduction of 'f'
    788   // and the second 'h'.
    789   template<typename T> void f(const T *);
    790   template<typename T> void g(T *, const T * = 0);
    791   template<typename T> void h(T *) { T::error; }
    792   template<typename T> void h(const T *);
    793   void i() {
    794     f(&i);
    795     g(&i);
    796     h(&i);
    797   }
    798 }
    799 
    800 namespace dr470 { // dr470: yes
    801   template<typename T> struct A {
    802     struct B {};
    803   };
    804   template<typename T> struct C {
    805   };
    806 
    807   template struct A<int>; // expected-note {{previous}}
    808   template struct A<int>::B; // expected-error {{duplicate explicit instantiation}}
    809 
    810   // ok, instantiating C<char> doesn't instantiate base class members.
    811   template struct A<char>;
    812   template struct C<char>;
    813 }
    814 
    815 namespace dr471 { // dr471: yes
    816   struct A { int n; };
    817   struct B : private virtual A {};
    818   struct C : protected virtual A {};
    819   struct D : B, C { int f() { return n; } };
    820   struct E : private virtual A {
    821     using A::n;
    822   };
    823   struct F : E, B { int f() { return n; } };
    824   struct G : virtual A {
    825   private:
    826     using A::n; // expected-note {{here}}
    827   };
    828   struct H : B, G { int f() { return n; } }; // expected-error {{private}}
    829 }
    830 
    831 namespace dr474 { // dr474: yes
    832   namespace N {
    833     struct S {
    834       void f();
    835     };
    836   }
    837   void N::S::f() {
    838     void g(); // expected-note {{previous}}
    839   }
    840   int g();
    841   namespace N {
    842     int g(); // expected-error {{cannot be overloaded}}
    843   }
    844 }
    845 
    846 // dr475 FIXME write a codegen test
    847 
    848 namespace dr477 { // dr477: 3.5
    849   struct A {
    850     explicit A();
    851     virtual void f();
    852   };
    853   struct B {
    854     friend explicit A::A(); // expected-error {{'explicit' is invalid in friend declarations}}
    855     friend virtual void A::f(); // expected-error {{'virtual' is invalid in friend declarations}}
    856   };
    857   explicit A::A() {} // expected-error {{can only be specified inside the class definition}}
    858   virtual void A::f() {} // expected-error {{can only be specified inside the class definition}}
    859 }
    860 
    861 namespace dr478 { // dr478: yes
    862   struct A { virtual void f() = 0; }; // expected-note {{unimplemented}}
    863   void f(A *a);
    864   void f(A a[10]); // expected-error {{array of abstract class type}}
    865 }
    866 
    867 namespace dr479 { // dr479: yes
    868   struct S {
    869     S();
    870   private:
    871     S(const S&); // expected-note +{{here}}
    872     ~S(); // expected-note +{{here}}
    873   };
    874   void f() {
    875     throw S();
    876     // expected-error@-1 {{temporary of type 'dr479::S' has private destructor}}
    877     // expected-error@-2 {{calling a private constructor}}
    878     // expected-error@-3 {{exception object of type 'dr479::S' has private destructor}}
    879 #if __cplusplus < 201103L
    880     // expected-error@-5 {{C++98 requires an accessible copy constructor}}
    881 #endif
    882   }
    883   void g() {
    884     S s; // expected-error {{private destructor}}}
    885     throw s;
    886     // expected-error@-1 {{calling a private constructor}}
    887     // expected-error@-2 {{exception object of type 'dr479::S' has private destructor}}
    888   }
    889   void h() {
    890     try {
    891       f();
    892       g();
    893     } catch (S s) {
    894       // expected-error@-1 {{calling a private constructor}}
    895       // expected-error@-2 {{variable of type 'dr479::S' has private destructor}}
    896     }
    897   }
    898 }
    899 
    900 namespace dr480 { // dr480: yes
    901   struct A { int n; };
    902   struct B : A {};
    903   struct C : virtual B {};
    904   struct D : C {};
    905 
    906   int A::*a = &A::n;
    907   int D::*b = a; // expected-error {{virtual base}}
    908 
    909   extern int D::*c;
    910   int A::*d = static_cast<int A::*>(c); // expected-error {{virtual base}}
    911 
    912   D *e;
    913   A *f = e;
    914   D *g = static_cast<D*>(f); // expected-error {{virtual base}}
    915 
    916   extern D &i;
    917   A &j = i;
    918   D &k = static_cast<D&>(j); // expected-error {{virtual base}}
    919 }
    920 
    921 namespace dr481 { // dr481: yes
    922   template<class T, T U> class A { T *x; };
    923   T *x; // expected-error {{unknown type}}
    924 
    925   template<class T *U> class B { T *x; };
    926   T *y; // ok
    927 
    928   struct C {
    929     template<class T> void f(class D *p);
    930   };
    931   D *z; // ok
    932 
    933   template<typename A = C, typename C = A> struct E {
    934     void f() {
    935       typedef ::dr481::C c; // expected-note {{previous}}
    936       typedef C c; // expected-error {{different type}}
    937     }
    938   };
    939   template struct E<>; // ok
    940   template struct E<int>; // expected-note {{instantiation of}}
    941 
    942   template<template<typename U_no_typo_correction> class A,
    943            A<int> *B,
    944            U_no_typo_correction *C> // expected-error {{unknown type}}
    945   struct F {
    946     U_no_typo_correction *x; // expected-error {{unknown type}}
    947   };
    948 
    949   template<template<class H *> class> struct G {
    950     H *x;
    951   };
    952   H *q;
    953 
    954   typedef int N;
    955   template<N X, typename N, template<N Y> class T> struct I;
    956   template<char*> struct J;
    957   I<123, char*, J> *j;
    958 }
    959 
    960 namespace dr482 { // dr482: 3.5
    961   extern int a;
    962   void f();
    963 
    964   int dr482::a = 0; // expected-warning {{extra qualification}}
    965   void dr482::f() {} // expected-warning {{extra qualification}}
    966 
    967   inline namespace X { // expected-error 0-1{{C++11 feature}}
    968     extern int b;
    969     void g();
    970     struct S;
    971   }
    972   int dr482::b = 0; // expected-warning {{extra qualification}}
    973   void dr482::g() {} // expected-warning {{extra qualification}}
    974   struct dr482::S {}; // expected-warning {{extra qualification}}
    975 
    976   void dr482::f(); // expected-warning {{extra qualification}}
    977   void dr482::g(); // expected-warning {{extra qualification}}
    978 
    979   // FIXME: The following are valid in DR482's wording, but these are bugs in
    980   // the wording which we deliberately don't implement.
    981   namespace N { typedef int type; }
    982   typedef int N::type; // expected-error {{typedef declarator cannot be qualified}}
    983   struct A {
    984     struct B;
    985     struct A::B {}; // expected-error {{extra qualification}}
    986 
    987 #if __cplusplus >= 201103L
    988     enum class C;
    989     enum class A::C {}; // expected-error {{extra qualification}}
    990 #endif
    991   };
    992 }
    993 
    994 namespace dr483 { // dr483: yes
    995   namespace climits {
    996     int check1[__SCHAR_MAX__ >= 127 ? 1 : -1];
    997     int check2[__SHRT_MAX__ >= 32767 ? 1 : -1];
    998     int check3[__INT_MAX__ >= 32767 ? 1 : -1];
    999     int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1];
   1000     int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1];
   1001 #if __cplusplus < 201103L
   1002     // expected-error@-2 {{extension}}
   1003 #endif
   1004   }
   1005   namespace cstdint {
   1006     int check1[__PTRDIFF_WIDTH__ >= 16 ? 1 : -1];
   1007     int check2[__SIG_ATOMIC_WIDTH__ >= 8 ? 1 : -1];
   1008     int check3[__SIZE_WIDTH__ >= 16 ? 1 : -1];
   1009     int check4[__WCHAR_WIDTH__ >= 8 ? 1 : -1];
   1010     int check5[__WINT_WIDTH__ >= 16 ? 1 : -1];
   1011   }
   1012 }
   1013 
   1014 namespace dr484 { // dr484: yes
   1015   struct A {
   1016     A();
   1017     void f();
   1018   };
   1019   typedef const A CA;
   1020   void CA::f() {
   1021     this->~CA();
   1022     this->CA::~A();
   1023     this->CA::A::~A();
   1024   }
   1025   CA::A() {}
   1026 
   1027   struct B : CA {
   1028     B() : CA() {}
   1029     void f() { return CA::f(); }
   1030   };
   1031 
   1032   struct C;
   1033   typedef C CT; // expected-note {{here}}
   1034   struct CT {}; // expected-error {{conflicts with typedef}}
   1035 
   1036   namespace N {
   1037     struct D;
   1038     typedef D DT; // expected-note {{here}}
   1039   }
   1040   struct N::DT {}; // expected-error {{conflicts with typedef}}
   1041 
   1042   typedef struct {
   1043     S(); // expected-error {{requires a type}}
   1044   } S;
   1045 }
   1046 
   1047 namespace dr485 { // dr485: yes
   1048   namespace N {
   1049     struct S {};
   1050     int operator+(S, S);
   1051     template<typename T> int f(S);
   1052   }
   1053   template<typename T> int f();
   1054 
   1055   N::S s;
   1056   int a = operator+(s, s);
   1057   int b = f<int>(s);
   1058 }
   1059 
   1060 namespace dr486 { // dr486: yes
   1061   template<typename T> T f(T *); // expected-note 2{{substitution failure}}
   1062   int &f(...);
   1063 
   1064   void g();
   1065   int n[10];
   1066 
   1067   void h() {
   1068     int &a = f(&g);
   1069     int &b = f(&n);
   1070     f<void()>(&g); // expected-error {{no match}}
   1071     f<int[10]>(&n); // expected-error {{no match}}
   1072   }
   1073 }
   1074 
   1075 namespace dr487 { // dr487: yes
   1076   enum E { e };
   1077   int operator+(int, E);
   1078   int i[4 + e]; // expected-error 2{{variable length array}}
   1079 }
   1080 
   1081 namespace dr488 { // dr488: yes c++11
   1082   template <typename T> void f(T);
   1083   void f(int);
   1084   void g() {
   1085     // FIXME: It seems CWG thought this should be a SFINAE failure prior to
   1086     // allowing local types as template arguments. In C++98, we should either
   1087     // allow local types as template arguments or treat this as a SFINAE
   1088     // failure.
   1089     enum E { e };
   1090     f(e);
   1091 #if __cplusplus < 201103L
   1092     // expected-error@-2 {{local type}}
   1093 #endif
   1094   }
   1095 }
   1096 
   1097 // dr489: na
   1098 
   1099 namespace dr490 { // dr490: yes
   1100   template<typename T> struct X {};
   1101 
   1102   struct A {
   1103     typedef int T;
   1104     struct K {}; // expected-note {{declared}}
   1105 
   1106     int f(T);
   1107     int g(T);
   1108     int h(X<T>);
   1109     int X<T>::*i(); // expected-note {{previous}}
   1110     int K::*j();
   1111 
   1112     template<typename T> T k();
   1113 
   1114     operator X<T>();
   1115   };
   1116 
   1117   struct B {
   1118     typedef char T;
   1119     typedef int U;
   1120     friend int A::f(T);
   1121     friend int A::g(U);
   1122     friend int A::h(X<T>);
   1123 
   1124     // FIXME: Per this DR, these two are valid! That is another defect
   1125     // (no number yet...) which will eventually supersede this one.
   1126     friend int X<T>::*A::i(); // expected-error {{return type}}
   1127     friend int K::*A::j(); // expected-error {{undeclared identifier 'K'; did you mean 'A::K'?}}
   1128 
   1129     // ok, lookup finds B::T, not A::T, so return type matches
   1130     friend char A::k<T>();
   1131     friend int A::k<U>();
   1132 
   1133     // A conversion-type-id in a conversion-function-id is always looked up in
   1134     // the class of the conversion function first.
   1135     friend A::operator X<T>();
   1136   };
   1137 }
   1138 
   1139 namespace dr491 { // dr491: dup 413
   1140   struct A {} a, b[3] = { a, {} };
   1141   A c[2] = { a, {}, b[1] }; // expected-error {{excess elements}}
   1142 }
   1143 
   1144 // dr492 FIXME write a codegen test
   1145 
   1146 namespace dr493 { // dr493: dup 976
   1147   struct X {
   1148     template <class T> operator const T &() const;
   1149   };
   1150   void f() {
   1151     if (X()) {
   1152     }
   1153   }
   1154 }
   1155 
   1156 namespace dr494 { // dr494: dup 372
   1157   class A {
   1158     class B {};
   1159     friend class C;
   1160   };
   1161   class C : A::B {
   1162     A::B x;
   1163     class D : A::B {
   1164       A::B y;
   1165     };
   1166   };
   1167 }
   1168 
   1169 namespace dr495 { // dr495: 3.5
   1170   template<typename T>
   1171   struct S {
   1172     operator int() { return T::error; }
   1173     template<typename U> operator U();
   1174   };
   1175   S<int> s;
   1176   long n = s;
   1177 
   1178   template<typename T>
   1179   struct S2 {
   1180     template<typename U> operator U();
   1181     operator int() { return T::error; }
   1182   };
   1183   S2<int> s2;
   1184   long n2 = s2;
   1185 }
   1186 
   1187 namespace dr496 { // dr496: no
   1188   struct A { int n; };
   1189   struct B { volatile int n; };
   1190   int check1[ __is_trivially_copyable(const int) ? 1 : -1];
   1191   int check2[!__is_trivially_copyable(volatile int) ? 1 : -1];
   1192   int check3[ __is_trivially_constructible(A, const A&) ? 1 : -1];
   1193   // FIXME: This is wrong.
   1194   int check4[ __is_trivially_constructible(B, const B&) ? 1 : -1];
   1195   int check5[ __is_trivially_assignable(A, const A&) ? 1 : -1];
   1196   // FIXME: This is wrong.
   1197   int check6[ __is_trivially_assignable(B, const B&) ? 1 : -1];
   1198 }
   1199 
   1200 namespace dr497 { // dr497: yes
   1201   void before() {
   1202     struct S {
   1203       mutable int i;
   1204     };
   1205     const S cs; // expected-error {{default initialization}}
   1206     int S::*pm = &S::i;
   1207     cs.*pm = 88; // expected-error {{not assignable}}
   1208   }
   1209 
   1210   void after() {
   1211     struct S {
   1212       S() : i(0) {}
   1213       mutable int i;
   1214     };
   1215     const S cs;
   1216     int S::*pm = &S::i;
   1217     cs.*pm = 88; // expected-error {{not assignable}}
   1218   }
   1219 }
   1220 
   1221 namespace dr499 { // dr499: yes
   1222   extern char str[];
   1223   void f() { throw str; }
   1224 }
   1225