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