Home | History | Annotate | Download | only in drs
      1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      3 // RUN: %clang_cc1 -std=c++1y %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      4 
      5 namespace dr300 { // dr300: yes
      6   template<typename R, typename A> void f(R (&)(A)) {}
      7   int g(int);
      8   void h() { f(g); }
      9 }
     10 
     11 namespace dr301 { // dr301: yes
     12   // see also dr38
     13   struct S;
     14   template<typename T> void operator+(T, T);
     15   void operator-(S, S);
     16 
     17   void f() {
     18     bool a = (void(*)(S, S))operator+<S> <
     19              (void(*)(S, S))operator+<S>;
     20     bool b = (void(*)(S, S))operator- <
     21              (void(*)(S, S))operator-;
     22     bool c = (void(*)(S, S))operator+ <
     23              (void(*)(S, S))operator-; // expected-error {{expected '>'}}
     24   }
     25 
     26   template<typename T> void f() {
     27     typename T::template operator+<int> a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
     28     // FIXME: This shouldn't say (null).
     29     class T::template operator+<int> b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
     30     enum T::template operator+<int> c; // expected-error {{expected identifier}} expected-error {{does not declare anything}}
     31     enum T::template operator+<int>::E d; // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} expected-error {{forward reference}}
     32     enum T::template X<int>::E e;
     33     T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}}
     34     T::template operator+<int>(0); // ok
     35   }
     36 
     37   template<typename T> class operator&<T*> {}; // expected-error +{{}}
     38   template<typename T> class T::operator& {}; // expected-error +{{}}
     39   template<typename T> class S::operator&<T*> {}; // expected-error +{{}}
     40 }
     41 
     42 namespace dr302 { // dr302: yes
     43   struct A { A(); ~A(); };
     44 #if __cplusplus < 201103L
     45   struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}}
     46     const int n; // expected-note {{declared here}}
     47     A a;
     48   } b = B(); // expected-note {{first required here}}
     49   // Trivial default constructor C::C() is not called here.
     50   struct C {
     51     const int n;
     52   } c = C();
     53 #else
     54   struct B {
     55     const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
     56     A a;
     57   } b = B(); // expected-error {{call to implicitly-deleted default constructor}}
     58   // C::C() is called here, because even though it's trivial, it's deleted.
     59   struct C {
     60     const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
     61   } c = C(); // expected-error {{call to implicitly-deleted default constructor}}
     62   struct D {
     63     const int n = 0;
     64   } d = D();
     65 #endif
     66 }
     67 
     68 // dr303: na
     69 
     70 namespace dr304 { // dr304: yes
     71   typedef int &a;
     72   int n = a(); // expected-error {{requires an initializer}}
     73 
     74   struct S { int &b; };
     75   int m = S().b;
     76 #if __cplusplus < 201103L
     77   // expected-error@-3 {{requires an initializer}}
     78   // expected-note@-3 {{in value-initialization}}
     79 #else
     80   // expected-error@-5 {{deleted}}
     81   // expected-note@-7 {{reference}}
     82 #endif
     83 }
     84 
     85 namespace dr305 { // dr305: no
     86   struct A {
     87     typedef A C;
     88   };
     89   void f(A *a) {
     90     struct A {};
     91     a->~A();
     92     a->~C();
     93   }
     94   typedef A B;
     95   void g(B *b) {
     96     b->~B();
     97     b->~C();
     98   }
     99   void h(B *b) {
    100     struct B {}; // expected-note {{declared here}}
    101     b->~B(); // expected-error {{does not match}}
    102   }
    103 
    104   template<typename T> struct X {};
    105   void i(X<int>* x) {
    106     struct X {};
    107     x->~X<int>();
    108     x->~X();
    109     x->~X<char>(); // expected-error {{no member named}}
    110   }
    111 
    112   // FIXME: This appears to be valid (but allowing the nested types might be a
    113   // defect).
    114   template<typename> struct Nested {
    115     template<typename> struct Nested {};
    116   };
    117   void testNested(Nested<int> n) { n.~Nested<int>(); } // expected-error {{no member named}}
    118 #if __cplusplus < 201103L
    119   // expected-error@-2 {{ambiguous}}
    120   // expected-note@-6 {{here}}
    121   // expected-note@-6 {{here}}
    122 #endif
    123 
    124 #if __cplusplus >= 201103L
    125   struct Y {
    126     template<typename T> using T1 = Y;
    127   };
    128   template<typename T> using T2 = Y;
    129   void j(Y *y) {
    130     y->~T1<int>();
    131     y->~T2<int>();
    132   }
    133   struct Z {
    134     template<typename T> using T2 = T;
    135   };
    136   void k(Z *z) {
    137     // FIXME: This diagnostic is terrible.
    138     z->~T1<int>(); // expected-error {{'T1' following the 'template' keyword does not refer to a template}} expected-error +{{}}
    139     z->~T2<int>(); // expected-error {{no member named '~int'}}
    140     z->~T2<Z>();
    141   }
    142 
    143   // FIXME: This is valid.
    144   namespace Q {
    145     template<typename A> struct R {};
    146   }
    147   template<typename A> using R = Q::R<int>;
    148   void qr(Q::R<int> x) { x.~R<char>(); } // expected-error {{no member named}}
    149 #endif
    150 }
    151 
    152 namespace dr306 { // dr306: no
    153   // FIXME: dup 39
    154   // FIXME: This should be accepted.
    155   struct A { struct B {}; }; // expected-note 2{{member}}
    156   struct C { typedef A::B B; }; // expected-note {{member}}
    157   struct D : A, A::B, C {};
    158   D::B b; // expected-error {{found in multiple base classes of different types}}
    159 }
    160 
    161 // dr307: na
    162 
    163 namespace dr308 { // dr308: yes
    164   // This is mostly an ABI library issue.
    165   struct A {};
    166   struct B : A {};
    167   struct C : A {};
    168   struct D : B, C {};
    169   void f() {
    170     try {
    171       throw D();
    172     } catch (const A&) {
    173       // unreachable
    174     } catch (const B&) {
    175       // get here instead
    176     }
    177   }
    178 }
    179 
    180 // dr309: dup 485
    181 
    182 namespace dr311 { // dr311: yes
    183   namespace X { namespace Y {} }
    184   namespace X::Y {} // expected-error {{must define each namespace separately}}
    185   namespace X {
    186     namespace X::Y {} // expected-error {{must define each namespace separately}}
    187   }
    188   // FIXME: The diagnostics here are not very good.
    189   namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}}
    190 }
    191 
    192 // dr312: dup 616
    193 
    194 namespace dr313 { // dr313: dup 299 c++11
    195   struct A { operator int() const; };
    196   int *p = new int[A()];
    197 #if __cplusplus < 201103L
    198   // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}}
    199 #endif
    200 }
    201 
    202 namespace dr314 { // dr314: dup 1710
    203   template<typename T> struct A {
    204     template<typename U> struct B {};
    205   };
    206   template<typename T> struct C : public A<T>::template B<T> {
    207     C() : A<T>::template B<T>() {}
    208   };
    209 }
    210 
    211 // dr315: na
    212 // dr316: sup 1004
    213 
    214 namespace dr317 { // dr317: 3.5
    215   void f() {} // expected-note {{previous}}
    216   inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}}
    217 
    218   int g();
    219   int n = g();
    220   inline int g() { return 0; }
    221 
    222   int h();
    223   int m = h();
    224   int h() { return 0; } // expected-note {{previous}}
    225   inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}}
    226 }
    227 
    228 namespace dr318 { // dr318: sup 1310
    229   struct A {};
    230   struct A::A a;
    231 }
    232 
    233 namespace dr319 { // dr319: no
    234   // FIXME: dup dr389
    235   // FIXME: We don't have a diagnostic for a name with linkage
    236   //        having a type without linkage.
    237   typedef struct {
    238     int i;
    239   } *ps;
    240   extern "C" void f(ps);
    241   void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
    242 
    243   static enum { e } a1;
    244   enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
    245 
    246   enum { n1 = 1u };
    247   typedef int (*pa)[n1];
    248   pa parr; // ok, type has linkage despite using 'n1'
    249 
    250   template<typename> struct X {};
    251 
    252   void f() {
    253     struct A { int n; };
    254     extern A a; // FIXME: ill-formed
    255     X<A> xa;
    256 
    257     typedef A B;
    258     extern B b; // FIXME: ill-formed
    259     X<B> xb;
    260 
    261     const int n = 1;
    262     typedef int (*C)[n];
    263     extern C c; // ok
    264     X<C> xc;
    265   }
    266 #if __cplusplus < 201103L
    267   // expected-error@-12 {{uses local type 'A'}}
    268   // expected-error@-9 {{uses local type 'A'}}
    269 #endif
    270 }
    271 
    272 namespace dr320 { // dr320: yes
    273 #if __cplusplus >= 201103L
    274   struct X {
    275     constexpr X() {}
    276     constexpr X(const X &x) : copies(x.copies + 1) {}
    277     unsigned copies = 0;
    278   };
    279   constexpr X f(X x) { return x; }
    280   constexpr unsigned g(X x) { return x.copies; }
    281   static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value");
    282 #endif
    283 }
    284 
    285 namespace dr321 { // dr321: dup 557
    286   namespace N {
    287     template<int> struct A {
    288       template<int> struct B;
    289     };
    290     template<> template<> struct A<0>::B<0>;
    291     void f(A<0>::B<0>);
    292   }
    293   template<> template<> struct N::A<0>::B<0> {};
    294 
    295   template<typename T> void g(T t) { f(t); }
    296   template void g(N::A<0>::B<0>);
    297 
    298   namespace N {
    299     template<typename> struct I { friend bool operator==(const I&, const I&); };
    300   }
    301   N::I<int> i, j;
    302   bool x = i == j;
    303 }
    304 
    305 namespace dr322 { // dr322: yes
    306   struct A {
    307     template<typename T> operator T&();
    308   } a;
    309   int &r = static_cast<int&>(a);
    310   int &s = a;
    311 }
    312 
    313 // dr323: no
    314 
    315 namespace dr324 { // dr324: yes
    316   struct S { int n : 1; } s; // expected-note 3{{bit-field is declared here}}
    317   int &a = s.n; // expected-error {{non-const reference cannot bind to bit-field}}
    318   int *b = &s.n; // expected-error {{address of bit-field}}
    319   int &c = (s.n = 0); // expected-error {{non-const reference cannot bind to bit-field}}
    320   int *d = &(s.n = 0); // expected-error {{address of bit-field}}
    321   int &e = true ? s.n : s.n; // expected-error {{non-const reference cannot bind to bit-field}}
    322   int *f = &(true ? s.n : s.n); // expected-error {{address of bit-field}}
    323   int &g = (void(), s.n); // expected-error {{non-const reference cannot bind to bit-field}}
    324   int *h = &(void(), s.n); // expected-error {{address of bit-field}}
    325 }
    326 
    327 namespace dr326 { // dr326: yes
    328   struct S {};
    329   int test[__is_trivially_constructible(S, const S&) ? 1 : -1];
    330 }
    331 
    332 namespace dr327 { // dr327: dup 538
    333   struct A;
    334   class A {};
    335 
    336   class B;
    337   struct B {};
    338 }
    339 
    340 namespace dr328 { // dr328: yes
    341   struct A; // expected-note 3{{forward declaration}}
    342   struct B { A a; }; // expected-error {{incomplete}}
    343   template<typename> struct C { A a; }; // expected-error {{incomplete}}
    344   A *p = new A[0]; // expected-error {{incomplete}}
    345 }
    346 
    347 namespace dr329 { // dr329: 3.5
    348   struct B {};
    349   template<typename T> struct A : B {
    350     friend void f(A a) { g(a); }
    351     friend void h(A a) { g(a); } // expected-error {{undeclared}}
    352     friend void i(B b) {} // expected-error {{redefinition}} expected-note {{previous}}
    353   };
    354   A<int> a;
    355   A<char> b; // expected-note {{instantiation}}
    356 
    357   void test() {
    358     h(a); // expected-note {{instantiation}}
    359   }
    360 }
    361 
    362 namespace dr331 { // dr331: yes
    363   struct A {
    364     A(volatile A&); // expected-note {{candidate}}
    365   } const a, b(a); // expected-error {{no matching constructor}}
    366 }
    367 
    368 namespace dr332 { // dr332: dup 557
    369   void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}}
    370   void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}}
    371   void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}}
    372 }
    373 
    374 namespace dr333 { // dr333: yes
    375   int n = 0;
    376   int f(int(n));
    377   int g((int(n)));
    378   int h = f(g);
    379 }
    380 
    381 namespace dr334 { // dr334: yes
    382   template<typename T> void f() {
    383     T x;
    384     f((x, 123));
    385   }
    386   struct S {
    387     friend S operator,(S, int);
    388     friend void f(S);
    389   };
    390   template void f<S>();
    391 }
    392 
    393 // dr335: no
    394 
    395 namespace dr336 { // dr336: yes
    396   namespace Pre {
    397     template<class T1> class A {
    398       template<class T2> class B {
    399         template<class T3> void mf1(T3);
    400         void mf2();
    401       };
    402     };
    403     template<> template<class X> class A<int>::B {};
    404     template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} // expected-error {{does not match}}
    405     template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
    406   }
    407   namespace Post {
    408     template<class T1> class A {
    409       template<class T2> class B {
    410         template<class T3> void mf1(T3);
    411         void mf2();
    412       };
    413     };
    414     template<> template<class X> class A<int>::B {
    415       template<class T> void mf1(T);
    416     };
    417     template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
    418     // FIXME: This diagnostic isn't very good.
    419     template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
    420   }
    421 }
    422 
    423 namespace dr337 { // dr337: yes
    424   template<typename T> void f(T (*)[1]);
    425   template<typename T> int &f(...);
    426 
    427   struct A { virtual ~A() = 0; };
    428   int &r = f<A>(0);
    429 
    430   // FIXME: The language rules here are completely broken. We cannot determine
    431   // whether an incomplete type is abstract. See DR1640, which will probably
    432   // supersede this one and remove this rule.
    433   struct B;
    434   int &s = f<B>(0); // expected-error {{of type 'void'}}
    435   struct B { virtual ~B() = 0; };
    436 }
    437 
    438 namespace dr339 { // dr339: yes
    439   template <int I> struct A { static const int value = I; };
    440 
    441   char xxx(int);
    442   char (&xxx(float))[2];
    443 
    444   template<class T> A<sizeof(xxx((T)0))> f(T) {} // expected-note {{candidate}}
    445 
    446   void test() {
    447     A<1> a = f(0);
    448     A<2> b = f(0.0f);
    449     A<3> c = f("foo"); // expected-error {{no matching function}}
    450   }
    451 
    452 
    453   char f(int);
    454   int f(...);
    455 
    456   template <class T> struct conv_int {
    457     static const bool value = sizeof(f(T())) == 1;
    458   };
    459 
    460   template <class T> bool conv_int2(A<sizeof(f(T()))> p);
    461 
    462   template<typename T> A<sizeof(f(T()))> make_A();
    463 
    464   int a[conv_int<char>::value ? 1 : -1];
    465   bool b = conv_int2<char>(A<1>());
    466   A<1> c = make_A<char>();
    467 }
    468 
    469 namespace dr340 { // dr340: yes
    470   struct A { A(int); };
    471   struct B { B(A, A, int); };
    472   int x, y;
    473   B b(A(x), A(y), 3);
    474 }
    475 
    476 namespace dr341 { // dr341: sup 1708
    477   namespace A {
    478     int n;
    479     extern "C" int &dr341_a = n; // expected-note {{previous}} expected-note {{declared with C language linkage here}}
    480   }
    481   namespace B {
    482     extern "C" int &dr341_a = dr341_a; // expected-error {{redefinition}}
    483   }
    484   extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}}
    485 }
    486 int dr341_a; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}}
    487 int dr341_b; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}}
    488 int dr341_c; // expected-note {{declared in global scope here}}
    489 int dr341_d; // expected-note {{declared in global scope here}}
    490 namespace dr341 {
    491   extern "C" int dr341_c; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}}
    492   extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}}
    493 
    494   namespace A { extern "C" int dr341_e; } // expected-note {{previous}}
    495   namespace B { extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}}
    496 }
    497 
    498 // dr342: na
    499 
    500 namespace dr343 { // dr343: no
    501   // FIXME: dup 1710
    502   template<typename T> struct A {
    503     template<typename U> struct B {};
    504   };
    505   // FIXME: In these contexts, the 'template' keyword is optional.
    506   template<typename T> struct C : public A<T>::B<T> { // expected-error {{use 'template'}}
    507     C() : A<T>::B<T>() {} // expected-error {{use 'template'}}
    508   };
    509 }
    510 
    511 namespace dr344 { // dr344: dup 1435
    512   struct A { inline virtual ~A(); };
    513   struct B { friend A::~A(); };
    514 }
    515 
    516 namespace dr345 { // dr345: yes
    517   struct A {
    518     struct X {};
    519     int X; // expected-note {{here}}
    520   };
    521   struct B {
    522     struct X {};
    523   };
    524   template <class T> void f(T t) { typename T::X x; } // expected-error {{refers to non-type member 'X'}}
    525   void f(A a, B b) {
    526     f(b);
    527     f(a); // expected-note {{instantiation}}
    528   }
    529 }
    530 
    531 // dr346: na
    532 
    533 namespace dr347 { // dr347: yes
    534   struct base {
    535     struct nested;
    536     static int n;
    537     static void f();
    538     void g();
    539   };
    540 
    541   struct derived : base {};
    542 
    543   struct derived::nested {}; // expected-error {{no struct named 'nested'}}
    544   int derived::n; // expected-error {{no member named 'n'}}
    545   void derived::f() {} // expected-error {{does not match any}}
    546   void derived::g() {} // expected-error {{does not match any}}
    547 }
    548 
    549 // dr348: na
    550 
    551 namespace dr349 { // dr349: no
    552   struct A {
    553     template <class T> operator T ***() {
    554       int ***p = 0;
    555       return p; // expected-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
    556     }
    557   };
    558 
    559   // FIXME: This is valid.
    560   A a;
    561   const int *const *const *p1 = a; // expected-note {{in instantiation of}}
    562 
    563   struct B {
    564     template <class T> operator T ***() {
    565       const int ***p = 0;
    566       return p;
    567     }
    568   };
    569 
    570   // FIXME: This is invalid.
    571   B b;
    572   const int *const *const *p2 = b;
    573 }
    574 
    575 // dr351: na
    576 
    577 namespace dr352 { // dr352: yes
    578   namespace example1 {
    579     namespace A {
    580       enum E {};
    581       template<typename R, typename A> void foo(E, R (*)(A)); // expected-note 2{{couldn't infer template argument 'R'}}
    582     }
    583 
    584     template<typename T> void arg(T);
    585     template<typename T> int arg(T) = delete; // expected-note {{here}} expected-error 0-1{{extension}}
    586 
    587     void f(A::E e) {
    588       foo(e, &arg); // expected-error {{no matching function}}
    589 
    590       using A::foo;
    591       foo<int, int>(e, &arg); // expected-error {{deleted}}
    592     }
    593 
    594     int arg(int);
    595 
    596     void g(A::E e) {
    597       foo(e, &arg); // expected-error {{no matching function}}
    598 
    599       using A::foo;
    600       foo<int, int>(e, &arg); // ok, uses non-template
    601     }
    602   }
    603 
    604   namespace contexts {
    605     template<int I> void f1(int (&)[I]);
    606     template<int I> void f2(int (&)[I+1]); // expected-note {{couldn't infer}}
    607     template<int I> void f3(int (&)[I+1], int (&)[I]);
    608     void f() {
    609       int a[4];
    610       int b[3];
    611       f1(a);
    612       f2(a); // expected-error {{no matching function}}
    613       f3(a, b);
    614     }
    615 
    616     template<int I> struct S {};
    617     template<int I> void g1(S<I>);
    618     template<int I> void g2(S<I+1>); // expected-note {{couldn't infer}}
    619     template<int I> void g3(S<I+1>, S<I>);
    620     void g() {
    621       S<4> a;
    622       S<3> b;
    623       g1(a);
    624       g2(a); // expected-error {{no matching function}}
    625       g3(a, b);
    626     }
    627 
    628     template<typename T> void h1(T = 0); // expected-note {{couldn't infer}}
    629     template<typename T> void h2(T, T = 0);
    630     void h() {
    631       h1(); // expected-error {{no matching function}}
    632       h1(0);
    633       h1<int>();
    634       h2(0);
    635     }
    636 
    637     template<typename T> int tmpl(T);
    638     template<typename R, typename A> void i1(R (*)(A)); // expected-note 3{{couldn't infer}}
    639     template<typename R, typename A> void i2(R, A, R (*)(A)); // expected-note {{not viable}}
    640     void i() {
    641       extern int single(int);
    642       i1(single);
    643       i2(0, 0, single);
    644 
    645       extern int ambig(float), ambig(int);
    646       i1(ambig); // expected-error {{no matching function}}
    647       i2(0, 0, ambig);
    648 
    649       extern void no_match(float), no_match(int);
    650       i1(no_match); // expected-error {{no matching function}}
    651       i2(0, 0, no_match); // expected-error {{no matching function}}
    652 
    653       i1(tmpl); // expected-error {{no matching function}}
    654       i2(0, 0, tmpl);
    655     }
    656   }
    657 
    658   template<typename T> struct is_int;
    659   template<> struct is_int<int> {};
    660 
    661   namespace example2 {
    662     template<typename T> int f(T (*p)(T)) { is_int<T>(); }
    663     int g(int);
    664     int g(char);
    665     int i = f(g);
    666   }
    667 
    668   namespace example3 {
    669     template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
    670     int g(int);
    671     char g(char);
    672     int i = f(1, g);
    673   }
    674 
    675   namespace example4 {
    676     template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
    677     char g(char);
    678     template <class T> T g(T);
    679     int i = f(1, g);
    680   }
    681 
    682   namespace example5 {
    683     template<int I> class A {};
    684     template<int I> void g(A<I+1>); // expected-note {{couldn't infer}}
    685     template<int I> void f(A<I>, A<I+1>);
    686     void h(A<1> a1, A<2> a2) {
    687       g(a1); // expected-error {{no matching function}}
    688       g<0>(a1);
    689       f(a1, a2);
    690     }
    691   }
    692 }
    693 
    694 // dr353 needs an IRGen test.
    695 
    696 namespace dr354 { // dr354: yes c++11
    697   // FIXME: Should we allow this in C++98 too?
    698   struct S {};
    699 
    700   template<int*> struct ptr {}; // expected-note +{{here}}
    701   ptr<0> p0;
    702   ptr<(int*)0> p1;
    703   ptr<(float*)0> p2;
    704   ptr<(int S::*)0> p3;
    705 #if __cplusplus < 201103L
    706   // expected-error@-5 {{does not refer to any decl}}
    707   // expected-error@-5 {{does not refer to any decl}}
    708   // expected-error@-5 {{does not refer to any decl}}
    709   // expected-error@-5 {{does not refer to any decl}}
    710 #else
    711   // expected-error@-10 {{must be cast}}
    712   // ok
    713   // expected-error@-10 {{does not match}}
    714   // expected-error@-10 {{does not match}}
    715 #endif
    716 
    717   template<int*> int both();
    718   template<int> int both();
    719   int b0 = both<0>();
    720   int b1 = both<(int*)0>();
    721 #if __cplusplus < 201103L
    722   // expected-error@-2 {{no matching function}}
    723   // expected-note@-6 {{candidate}}
    724   // expected-note@-6 {{candidate}}
    725 #endif
    726 
    727   template<int S::*> struct ptr_mem {}; // expected-note +{{here}}
    728   ptr_mem<0> m0;
    729   ptr_mem<(int S::*)0> m1;
    730   ptr_mem<(float S::*)0> m2;
    731   ptr_mem<(int *)0> m3;
    732 #if __cplusplus < 201103L
    733   // expected-error@-5 {{cannot be converted}}
    734   // expected-error@-5 {{is not a pointer to member constant}}
    735   // expected-error@-5 {{cannot be converted}}
    736   // expected-error@-5 {{cannot be converted}}
    737 #else
    738   // expected-error@-10 {{must be cast}}
    739   // ok
    740   // expected-error@-10 {{does not match}}
    741   // expected-error@-10 {{does not match}}
    742 #endif
    743 }
    744 
    745 struct dr355_S; // dr355: yes
    746 struct ::dr355_S {}; // expected-warning {{extra qualification}}
    747 namespace dr355 { struct ::dr355_S s; }
    748 
    749 // dr356: na
    750 
    751 namespace dr357 { // dr357: yes
    752   template<typename T> struct A {
    753     void f() const; // expected-note {{const qualified}}
    754   };
    755   template<typename T> void A<T>::f() {} // expected-error {{does not match}}
    756 
    757   struct B {
    758     template<typename T> void f();
    759   };
    760   template<typename T> void B::f() const {} // expected-error {{does not match}}
    761 }
    762 
    763 namespace dr358 { // dr358: yes
    764   extern "C" void dr358_f();
    765   namespace N {
    766     int var;
    767     extern "C" void dr358_f() { var = 10; }
    768   }
    769 }
    770 
    771 namespace dr359 { // dr359: yes
    772   // Note, the example in the DR is wrong; it doesn't contain an anonymous
    773   // union.
    774   struct E {
    775     union {
    776       struct {
    777         int x;
    778       } s;
    779     } v;
    780 
    781     union {
    782       struct { // expected-error {{extension}}
    783         int x;
    784       } s;
    785 
    786       struct S { // expected-error {{types cannot be declared in an anonymous union}}
    787         int x;
    788       } t;
    789 
    790       union { // expected-error {{extension}}
    791         int u;
    792       };
    793     };
    794   };
    795 }
    796 
    797 // dr362: na
    798 // dr363: na
    799 
    800 namespace dr364 { // dr364: yes
    801   struct S {
    802     static void f(int);
    803     void f(char);
    804   };
    805 
    806   void g() {
    807     S::f('a'); // expected-error {{call to non-static}}
    808     S::f(0);
    809   }
    810 }
    811 
    812 #if "foo" // expected-error {{invalid token}} dr366: yes
    813 #endif
    814 
    815 namespace dr367 { // dr367: yes
    816   // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
    817   // array as being a VLA!
    818   int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
    819   int b[true ? 4 : throw 0];
    820   int c[true ? *new int : 4]; // expected-error 2{{variable length array}}
    821   int d[true ? 4 : *new int];
    822 #if __cplusplus < 201103L
    823   // expected-error@-4 {{variable length array}} expected-error@-4 {{constant expression}}
    824   // expected-error@-3 {{variable length array}} expected-error@-3 {{constant expression}}
    825 #endif
    826 }
    827 
    828 namespace dr368 { // dr368: yes
    829   template<typename T, T> struct S {}; // expected-note {{here}}
    830   template<typename T> int f(S<T, T()> *); // expected-error {{function type}}
    831   //template<typename T> int g(S<T, (T())> *); // FIXME: crashes clang
    832   template<typename T> int g(S<T, true ? T() : T()> *); // expected-note {{cannot have type 'dr368::X'}}
    833   struct X {};
    834   int n = g<X>(0); // expected-error {{no matching}}
    835 }
    836 
    837 // dr370: na
    838 
    839 namespace dr372 { // dr372: no
    840   namespace example1 {
    841     template<typename T> struct X {
    842     protected:
    843       typedef T Type; // expected-note 2{{protected}}
    844     };
    845     template<typename T> struct Y {};
    846 
    847     // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
    848     // the protected member T1<T>::Type.
    849     template<typename T,
    850              template<typename> class T1,
    851              template<typename> class T2> struct Z1 :
    852       T1<T>,
    853       T2<typename T1<T>::Type> {}; // expected-error {{protected}}
    854 
    855     template<typename T,
    856              template<typename> class T1,
    857              template<typename> class T2> struct Z2 :
    858       T2<typename T1<T>::Type>, // expected-error {{protected}}
    859       T1<T> {};
    860 
    861     Z1<int, X, Y> z1; // expected-note {{instantiation of}}
    862     Z2<int, X, Y> z2; // expected-note {{instantiation of}}
    863   }
    864 
    865   namespace example2 {
    866     struct X {
    867     private:
    868       typedef int Type; // expected-note {{private}}
    869     };
    870     template<typename T> struct A {
    871       typename T::Type t; // expected-error {{private}}
    872     };
    873     A<X> ax; // expected-note {{instantiation of}}
    874   }
    875 
    876   namespace example3 {
    877     struct A {
    878     protected:
    879       typedef int N; // expected-note 2{{protected}}
    880     };
    881 
    882     template<typename T> struct B {};
    883     template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}}
    884     template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}}
    885 
    886     C<A> x; // expected-note {{instantiation of}}
    887     D<A> y; // expected-note {{instantiation of}}
    888   }
    889 
    890   namespace example4 {
    891     class A {
    892       class B {};
    893       friend class X;
    894     };
    895 
    896     struct X : A::B {
    897       A::B mx;
    898       class Y {
    899         A::B my;
    900       };
    901     };
    902   }
    903 }
    904 
    905 namespace dr373 { // dr373: no
    906   // FIXME: This is valid.
    907   namespace X { int dr373; } // expected-note 2{{here}}
    908   struct dr373 { // expected-note {{here}}
    909     void f() {
    910       using namespace dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
    911       int k = dr373; // expected-error {{does not refer to a value}}
    912 
    913       namespace Y = dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
    914       k = Y::dr373;
    915     }
    916   };
    917 }
    918 
    919 namespace dr374 { // dr374: yes c++11
    920   namespace N {
    921     template<typename T> void f();
    922     template<typename T> struct A { void f(); };
    923   }
    924   template<> void N::f<char>() {}
    925   template<> void N::A<char>::f() {}
    926   template<> struct N::A<int> {};
    927 #if __cplusplus < 201103L
    928   // expected-error@-4 {{extension}} expected-note@-7 {{here}}
    929   // expected-error@-4 {{extension}} expected-note@-7 {{here}}
    930   // expected-error@-4 {{extension}} expected-note@-8 {{here}}
    931 #endif
    932 }
    933 
    934 // dr375: dup 345
    935 // dr376: na
    936 
    937 namespace dr377 { // dr377: yes
    938   enum E { // expected-error {{enumeration values exceed range of largest integer}}
    939     a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
    940     b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
    941   };
    942 }
    943 
    944 // dr378: dup 276
    945 // dr379: na
    946 
    947 namespace dr381 { // dr381: yes
    948   struct A {
    949     int a;
    950   };
    951   struct B : virtual A {};
    952   struct C : B {};
    953   struct D : B {};
    954   struct E : public C, public D {};
    955   struct F : public A {};
    956   void f() {
    957     E e;
    958     e.B::a = 0; // expected-error {{ambiguous conversion}}
    959     F f;
    960     f.A::a = 1;
    961   }
    962 }
    963 
    964 namespace dr382 { // dr382: yes c++11
    965   // FIXME: Should we allow this in C++98 mode?
    966   struct A { typedef int T; };
    967   typename A::T t;
    968   typename dr382::A a;
    969 #if __cplusplus < 201103L
    970   // expected-error@-3 {{occurs outside of a template}}
    971   // expected-error@-3 {{occurs outside of a template}}
    972 #endif
    973   typename A b; // expected-error {{expected a qualified name}}
    974 }
    975 
    976 namespace dr383 { // dr383: yes
    977   struct A { A &operator=(const A&); };
    978   struct B { ~B(); };
    979   union C { C &operator=(const C&); };
    980   union D { ~D(); };
    981   int check[(__is_pod(A) || __is_pod(B) || __is_pod(C) || __is_pod(D)) ? -1 : 1];
    982 }
    983 
    984 namespace dr384 { // dr384: yes
    985   namespace N1 {
    986     template<typename T> struct Base {};
    987     template<typename T> struct X {
    988       struct Y : public Base<T> {
    989         Y operator+(int) const;
    990       };
    991       Y f(unsigned i) { return Y() + i; }
    992     };
    993   }
    994 
    995   namespace N2 {
    996     struct Z {};
    997     template<typename T> int *operator+(T, unsigned);
    998   }
    999 
   1000   int main() {
   1001     N1::X<N2::Z> v;
   1002     v.f(0);
   1003   }
   1004 }
   1005 
   1006 namespace dr385 { // dr385: yes
   1007   struct A { protected: void f(); };
   1008   struct B : A { using A::f; };
   1009   struct C : A { void g(B b) { b.f(); } };
   1010   void h(B b) { b.f(); }
   1011 
   1012   struct D { int n; }; // expected-note {{member}}
   1013   struct E : protected D {}; // expected-note 2{{protected}}
   1014   struct F : E { friend int i(E); };
   1015   int i(E e) { return e.n; } // expected-error {{protected base}} expected-error {{protected member}}
   1016 }
   1017 
   1018 namespace dr387 { // dr387: yes
   1019   namespace old {
   1020     template<typename T> class number {
   1021       number(int); // expected-note 2{{here}}
   1022       friend number gcd(number &x, number &y) {}
   1023     };
   1024 
   1025     void g() {
   1026       number<double> a(3), b(4); // expected-error 2{{private}}
   1027       a = gcd(a, b);
   1028       b = gcd(3, 4); // expected-error {{undeclared}}
   1029     }
   1030   }
   1031 
   1032   namespace newer {
   1033     template <typename T> class number {
   1034     public:
   1035       number(int);
   1036       friend number gcd(number x, number y) { return 0; }
   1037     };
   1038 
   1039     void g() {
   1040       number<double> a(3), b(4);
   1041       a = gcd(a, b);
   1042       b = gcd(3, 4); // expected-error {{undeclared}}
   1043     }
   1044   }
   1045 }
   1046 
   1047 // FIXME: dr388 needs codegen test
   1048 
   1049 namespace dr389 { // dr389: no
   1050   struct S {
   1051     typedef struct {} A;
   1052     typedef enum {} B;
   1053     typedef struct {} const C; // expected-note 0-2{{here}}
   1054     typedef enum {} const D; // expected-note 0-1{{here}}
   1055   };
   1056   template<typename> struct T {};
   1057 
   1058   struct WithLinkage1 {};
   1059   enum WithLinkage2 {};
   1060   typedef struct {} *WithLinkage3a, WithLinkage3b;
   1061   typedef enum {} WithLinkage4a, *WithLinkage4b;
   1062   typedef S::A WithLinkage5;
   1063   typedef const S::B WithLinkage6;
   1064   typedef int WithLinkage7;
   1065   typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
   1066   typedef T<WithLinkage5> WithLinkage9;
   1067 
   1068   typedef struct {} *WithoutLinkage1; // expected-note 0-1{{here}}
   1069   typedef enum {} const WithoutLinkage2; // expected-note 0-1{{here}}
   1070   // These two types don't have linkage even though they are externally visible
   1071   // and the ODR requires them to be merged across TUs.
   1072   typedef S::C WithoutLinkage3;
   1073   typedef S::D WithoutLinkage4;
   1074   typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
   1075 
   1076 #if __cplusplus >= 201103L
   1077   // This has linkage even though its template argument does not.
   1078   // FIXME: This is probably a defect.
   1079   typedef T<WithoutLinkage1> WithLinkage10;
   1080 #else
   1081   typedef int WithLinkage10; // dummy
   1082 
   1083   typedef T<WithLinkage1> GoodArg1;
   1084   typedef T<WithLinkage2> GoodArg2;
   1085   typedef T<WithLinkage3a> GoodArg3a;
   1086   typedef T<WithLinkage3b> GoodArg3b;
   1087   typedef T<WithLinkage4a> GoodArg4a;
   1088   typedef T<WithLinkage4b> GoodArg4b;
   1089   typedef T<WithLinkage5> GoodArg5;
   1090   typedef T<WithLinkage6> GoodArg6;
   1091   typedef T<WithLinkage7> GoodArg7;
   1092   typedef T<WithLinkage8> GoodArg8;
   1093   typedef T<WithLinkage9> GoodArg9;
   1094 
   1095   typedef T<WithoutLinkage1> BadArg1; // expected-error{{template argument uses}}
   1096   typedef T<WithoutLinkage2> BadArg2; // expected-error{{template argument uses}}
   1097   typedef T<WithoutLinkage3> BadArg3; // expected-error{{template argument uses}}
   1098   typedef T<WithoutLinkage4> BadArg4; // expected-error{{template argument uses}}
   1099   typedef T<WithoutLinkage5> BadArg5; // expected-error{{template argument uses}}
   1100 #endif
   1101 
   1102   extern WithLinkage1 withLinkage1;
   1103   extern WithLinkage2 withLinkage2;
   1104   extern WithLinkage3a withLinkage3a;
   1105   extern WithLinkage3b withLinkage3b;
   1106   extern WithLinkage4a withLinkage4a;
   1107   extern WithLinkage4b withLinkage4b;
   1108   extern WithLinkage5 withLinkage5;
   1109   extern WithLinkage6 withLinkage6;
   1110   extern WithLinkage7 withLinkage7;
   1111   extern WithLinkage8 withLinkage8;
   1112   extern WithLinkage9 withLinkage9;
   1113   extern WithLinkage10 withLinkage10;
   1114 
   1115   // FIXME: These are all ill-formed.
   1116   extern WithoutLinkage1 withoutLinkage1;
   1117   extern WithoutLinkage2 withoutLinkage2;
   1118   extern WithoutLinkage3 withoutLinkage3;
   1119   extern WithoutLinkage4 withoutLinkage4;
   1120   extern WithoutLinkage5 withoutLinkage5;
   1121 
   1122   // OK, extern "C".
   1123   extern "C" {
   1124     extern WithoutLinkage1 dr389_withoutLinkage1;
   1125     extern WithoutLinkage2 dr389_withoutLinkage2;
   1126     extern WithoutLinkage3 dr389_withoutLinkage3;
   1127     extern WithoutLinkage4 dr389_withoutLinkage4;
   1128     extern WithoutLinkage5 dr389_withoutLinkage5;
   1129   }
   1130 
   1131   // OK, defined.
   1132   WithoutLinkage1 withoutLinkageDef1;
   1133   WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
   1134   WithoutLinkage3 withoutLinkageDef3 = {};
   1135   WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
   1136   WithoutLinkage5 withoutLinkageDef5;
   1137 
   1138   void use(const void *);
   1139   void use_all() {
   1140     use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
   1141     use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
   1142     use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
   1143 
   1144     use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
   1145     use(&withoutLinkage4); use(&withoutLinkage5);
   1146 
   1147     use(&dr389_withoutLinkage1); use(&dr389_withoutLinkage2);
   1148     use(&dr389_withoutLinkage3); use(&dr389_withoutLinkage4);
   1149     use(&dr389_withoutLinkage5);
   1150 
   1151     use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
   1152     use(&withoutLinkageDef4); use(&withoutLinkageDef5);
   1153   }
   1154 
   1155   void local() {
   1156     // FIXME: This is ill-formed.
   1157     extern WithoutLinkage1 withoutLinkageLocal;
   1158   }
   1159 }
   1160 
   1161 namespace dr390 { // dr390: yes
   1162   template<typename T>
   1163   struct A {
   1164     A() { f(); } // expected-warning {{call to pure virt}}
   1165     virtual void f() = 0; // expected-note {{here}}
   1166     virtual ~A() = 0;
   1167   };
   1168   template<typename T> A<T>::~A() { T::error; } // expected-error {{cannot be used prior to}}
   1169   template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
   1170   struct B : A<int> { // expected-note 2{{in instantiation of}}
   1171     void f() {}
   1172   } b;
   1173 }
   1174 
   1175 namespace dr391 { // dr391: yes c++11
   1176   // FIXME: Should this apply to C++98 too?
   1177   class A { A(const A&); }; // expected-note 0-1{{here}}
   1178   A fa();
   1179   const A &a = fa();
   1180 #if __cplusplus < 201103L
   1181   // expected-error@-2 {{C++98 requires an accessible copy constructor}}
   1182 #endif
   1183 
   1184   struct B { B(const B&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}}
   1185   B fb();
   1186   const B &b = fb();
   1187 #if __cplusplus < 201103L
   1188   // expected-error@-2 {{deleted}}
   1189 #endif
   1190 
   1191   template<typename T>
   1192   struct C {
   1193     C(const C&) { T::error; }
   1194   };
   1195   C<int> fc();
   1196   const C<int> &c = fc();
   1197 }
   1198 
   1199 // dr392 FIXME write codegen test
   1200 // dr394: na
   1201 
   1202 namespace dr395 { // dr395: yes
   1203   struct S {
   1204     template <typename T, int N>(&operator T())[N]; // expected-error {{must use a typedef}}
   1205     template <typename T, int N> operator(T (&)[N])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}}
   1206     template <typename T> operator T *() const { return 0; }
   1207     template <typename T, typename U> operator T U::*() const { return 0; }
   1208     template <typename T, typename U> operator T (U::*)()() const { return 0; } // expected-error +{{}}
   1209   };
   1210 
   1211   struct null1_t {
   1212     template <class T, class U> struct ptr_mem_fun_t {
   1213       typedef T (U::*type)();
   1214     };
   1215 
   1216     template <class T, class U>
   1217     operator typename ptr_mem_fun_t<T, U>::type() const { // expected-note {{couldn't infer}}
   1218       return 0;
   1219     }
   1220   } null1;
   1221   int (S::*p)() = null1; // expected-error {{no viable conversion}}
   1222 
   1223   template <typename T> using id = T; // expected-error 0-1{{extension}}
   1224 
   1225   struct T {
   1226     template <typename T, int N> operator id<T[N]> &();
   1227     template <typename T, typename U> operator id<T (U::*)()>() const;
   1228   };
   1229 
   1230   struct null2_t {
   1231     template<class T, class U> using ptr_mem_fun_t = T (U::*)(); // expected-error 0-1{{extension}}
   1232     template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
   1233   } null2;
   1234   int (S::*q)() = null2;
   1235 }
   1236 
   1237 namespace dr396 { // dr396: yes
   1238   void f() {
   1239     auto int a(); // expected-error {{storage class on function}}
   1240     int (i); // expected-note {{previous}}
   1241     auto int (i); // expected-error {{redefinition}}
   1242 #if __cplusplus >= 201103L
   1243   // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}}
   1244 #endif
   1245   }
   1246 }
   1247 
   1248 // dr397: sup 1823
   1249 
   1250 namespace dr398 { // dr398: yes
   1251   namespace example1 {
   1252     struct S {
   1253       static int const I = 42;
   1254     };
   1255     template <int N> struct X {};
   1256     template <typename T> void f(X<T::I> *) {}
   1257     template <typename T> void f(X<T::J> *) {}
   1258     void foo() { f<S>(0); }
   1259   }
   1260 
   1261   namespace example2 {
   1262     template <int I> struct X {};
   1263     template <template <class T> class> struct Z {};
   1264     template <class T> void f(typename T::Y *) {} // expected-note 2{{substitution failure}}
   1265     template <class T> void g(X<T::N> *) {} // expected-note {{substitution failure}}
   1266     template <class T> void h(Z<T::template TT> *) {} // expected-note {{substitution failure}}
   1267     struct A {};
   1268     struct B {
   1269       int Y;
   1270     };
   1271     struct C {
   1272       typedef int N;
   1273     };
   1274     struct D {
   1275       typedef int TT;
   1276     };
   1277 
   1278     void test() {
   1279       f<A>(0); // expected-error {{no matching function}}
   1280       f<B>(0); // expected-error {{no matching function}}
   1281       g<C>(0); // expected-error {{no matching function}}
   1282       h<D>(0); // expected-error {{no matching function}}
   1283     }
   1284   }
   1285 }
   1286