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++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
      5 
      6 namespace std { struct type_info {}; }
      7 
      8 namespace dr601 { // dr601: yes
      9 #if __cplusplus >= 201103L
     10 #define MAX __LLONG_MAX__
     11 #else
     12 #define MAX __LONG_MAX__
     13 #endif
     14 
     15 #if 0x8000 < -1
     16 #error 0x8000 should be signed
     17 #endif
     18 
     19 #if MAX > 0xFFFFFFFF && 0x80000000 < -1
     20 #error 0x80000000 should be signed
     21 #endif
     22 
     23 #if __INT_MAX__ == 0x7FFFFFFF
     24 _Static_assert(0x80000000 < -1, "0x80000000 should be unsigned"); // expected-error {{C11}}
     25 #endif
     26 
     27 #if MAX > 0xFFFFFFFFFFFFFFFF && 0x8000000000000000 < -1
     28 #error 0x8000000000000000 should be signed
     29 #endif
     30 
     31 #if __cplusplus >= 201103L && __LLONG_MAX__ == 0x7FFFFFFFFFFFFFFF
     32 static_assert(0x8000000000000000 < -1, "0x8000000000000000 should be unsigned"); // expected-error {{C11}}
     33 #endif
     34 
     35 #undef MAX
     36 }
     37 
     38 namespace dr602 { // dr602: yes
     39   template<class T> struct A {
     40     template<class U> friend struct A;
     41   };
     42 
     43   template<class T> struct B {
     44     class C {
     45       template<class U> friend struct B;
     46       typedef int type;
     47     };
     48     typename C::type ct; // ok, befriended
     49   };
     50   B<int> b;
     51 }
     52 
     53 namespace dr603 { // dr603: yes
     54   template<unsigned char> struct S {};
     55   typedef S<'\001'> S1;
     56   typedef S<(1ul << __CHAR_BIT__) + 1> S1;
     57 #if __cplusplus >= 201103L
     58   // expected-error@-2 {{cannot be narrowed}}
     59 #endif
     60 }
     61 
     62 // dr604: na
     63 // dr605 needs IRGen test
     64 
     65 namespace dr606 { // dr606: yes
     66 #if __cplusplus >= 201103L
     67   template<typename T> struct S {};
     68   template<typename T> void f(S<T> &&); // expected-note {{no known conversion from 'S<int>' to 'S<int> &&'}}
     69   template<typename T> void g(T &&);
     70   template<typename T> void h(const T &&); // expected-note {{no known conversion from 'S<int>' to 'const dr606::S<int> &&'}}
     71 
     72   void test(S<int> s) {
     73     f(s); // expected-error {{no match}}
     74     g(s);
     75     h(s); // expected-error {{no match}}
     76 
     77     g(test);
     78     h(test); // ok, an rvalue reference can bind to a function lvalue
     79   }
     80 #endif
     81 }
     82 
     83 namespace dr608 { // dr608: yes
     84   struct A { virtual void f(); };
     85   struct B : A {};
     86   struct C : A { void f(); };
     87   struct D : B, C {};
     88 }
     89 
     90 int dr610[-0u == 0u ? 1 : -1]; // dr610: yes
     91 
     92 namespace dr611 { // dr611: yes
     93   int k;
     94   struct S { int &r; } s = { k ? k : k };
     95 }
     96 
     97 // dr612: na
     98 
     99 namespace dr613 { // dr613: yes c++11
    100   // see also n2253
    101   struct A { int n; static void f(); };
    102   int f(int);
    103   struct B { virtual void f(); };
    104   B &g(int);
    105 
    106   int an1 = sizeof(A::n);
    107   int an2 = sizeof(A::n + 1); // valid per dr850
    108   int an3 = sizeof A::n;
    109   int an4 = sizeof(f(A::n));
    110   int an5 = sizeof(g(A::n));
    111   const std::type_info &an6 = typeid(A::n);
    112   const std::type_info &an7 = typeid(A::n + 1);
    113   const std::type_info &an8 = typeid(f(A::n));
    114   const std::type_info &an9 = typeid(g(A::n)); // expected-error {{non-static}}
    115 #if __cplusplus < 201103L
    116   // expected-error@-10 {{non-static}}
    117   // expected-error@-10 {{non-static}}
    118   // expected-error@-10 {{non-static}}
    119   // expected-error@-10 {{non-static}}
    120   // expected-error@-10 {{non-static}}
    121   // expected-error@-10 {{non-static}}
    122   // expected-error@-10 {{non-static}}
    123   // expected-error@-10 {{non-static}}
    124 #endif
    125 
    126   void A::f() {
    127     int an1 = sizeof n;
    128     const std::type_info &an2 = typeid(n + 1);
    129 #if __cplusplus < 201103L
    130   // expected-error@-3 {{static}}
    131   // expected-error@-3 {{static}}
    132 #endif
    133     const std::type_info &an3 = typeid(g(n)); // expected-error {{static}}
    134   }
    135 }
    136 
    137 int dr614_a[(-1) / 2 == 0 ? 1 : -1]; // dr614: yes
    138 int dr614_b[(-1) % 2 == -1 ? 1 : -1];
    139 
    140 namespace dr615 { // dr615: yes
    141   int f();
    142   static int n = f();
    143 }
    144 
    145 namespace dr616 { // dr616: no
    146 #if __cplusplus >= 201103L
    147   struct S { int n; } s;
    148   // FIXME: These should all be 'int &&'
    149   using T = decltype(S().n); // expected-note 2{{previous}}
    150   using T = decltype(static_cast<S&&>(s).n);
    151   using T = decltype(S().*&S::n);
    152   using T = decltype(static_cast<S&&>(s).*&S::n); // expected-error {{different type}}
    153   using T = int&&; // expected-error {{different type}}
    154 #endif
    155 }
    156 
    157 namespace dr618 { // dr618: yes
    158 #if (unsigned)-1 > 0
    159 #error wrong
    160 #endif
    161 }
    162 
    163 namespace dr619 { // dr619: yes
    164   extern int x[10];
    165   struct S { static int x[10]; };
    166 
    167   int x[];
    168   _Static_assert(sizeof(x) == sizeof(int) * 10, ""); // expected-error {{C11}}
    169   extern int x[];
    170   _Static_assert(sizeof(x) == sizeof(int) * 10, ""); // expected-error {{C11}}
    171 
    172   int S::x[];
    173   _Static_assert(sizeof(S::x) == sizeof(int) * 10, ""); // expected-error {{C11}}
    174 
    175   void f() {
    176     extern int x[];
    177     sizeof(x); // expected-error {{incomplete}}
    178   }
    179 }
    180 
    181 // dr620: dup 568
    182 
    183 namespace dr621 {
    184   template<typename T> T f();
    185   template<> int f() {} // expected-note {{previous}}
    186   template<> int f<int>() {} // expected-error {{redefinition}}
    187 }
    188 
    189 // dr623: na
    190 // FIXME: Add documentation saying we allow invalid pointer values.
    191 
    192 // dr624 needs an IRGen check.
    193 
    194 namespace dr625 { // dr625: yes
    195   template<typename T> struct A {};
    196   A<auto> x = A<int>(); // expected-error {{'auto' not allowed in template argument}} expected-error 0-1{{extension}}
    197   void f(int);
    198   void (*p)(auto) = f; // expected-error {{'auto' not allowed in function prototype}} expected-error 0-1{{extension}}
    199 }
    200 
    201 namespace dr626 { // dr626: yes
    202 #define STR(x) #x
    203   char c[2] = STR(c); // ok, type matches
    204   wchar_t w[2] = STR(w); // expected-error {{initializing wide char array with non-wide string literal}}
    205 }
    206 
    207 namespace dr627 { // dr627: yes
    208   void f() {
    209     true a = 0; // expected-error +{{}} expected-warning {{unused}}
    210   }
    211 }
    212 
    213 // dr628: na
    214 
    215 namespace dr629 { // dr629: yes
    216   typedef int T;
    217   int n = 1;
    218   void f() {
    219     auto T = 2;
    220 #if __cplusplus < 201103L
    221     // expected-error@-2 {{expected unqualified-id}}
    222 #else
    223     // expected-note@-4 {{previous}}
    224 #endif
    225 
    226     auto T(n);
    227 #if __cplusplus >= 201103L
    228     // expected-error@-2 {{redefinition of 'T'}}
    229 #endif
    230   }
    231 }
    232 
    233 namespace dr630 { // dr630: yes
    234 const bool MB_EQ_WC =
    235     ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' &&
    236     '\n' == L'\n' && //
    237     'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' &&
    238     'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' &&
    239     'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' &&
    240     'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' &&
    241     'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' &&
    242     'z' == L'z' && //
    243     'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' &&
    244     'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' &&
    245     'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' &&
    246     'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' &&
    247     'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' &&
    248     'Z' == L'Z' && //
    249     '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' &&
    250     '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' &&
    251     '9' == L'9' && //
    252     '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' &&
    253     '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' &&
    254     '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' &&
    255     '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' &&
    256     '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' &&
    257     ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\'';
    258 #if __STDC_MB_MIGHT_NEQ_WC__
    259 #ifndef __FreeBSD__ // PR22208, FreeBSD expects us to give a bad (but conforming) answer here.
    260 _Static_assert(!MB_EQ_WC, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation"); // expected-error {{C11}}
    261 #endif
    262 #else
    263 _Static_assert(MB_EQ_WC, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs"); // expected-error {{C11}}
    264 #endif
    265 }
    266 
    267 // dr631: na
    268 
    269 namespace dr632 { // dr632: yes
    270   struct S { int n; } s = {{5}}; // expected-warning {{braces}}
    271 }
    272 
    273 // dr633: na
    274 // see also n2993
    275 
    276 namespace dr634 { // dr634: yes
    277   struct S { S(); S(const S&); virtual void f(); ~S(); };
    278   int f(...);
    279   char f(int);
    280   template<typename T> int (&g(T))[sizeof f(T())];
    281   int (&a)[sizeof(int)] = g(S());
    282   int (&b)[1] = g(0);
    283   int k = f(S()); // expected-error {{cannot pass}}
    284 }
    285 
    286 namespace dr635 { // dr635: yes
    287   template<typename T> struct A { A(); ~A(); };
    288   template<typename T> A<T>::A<T>() {} // expected-error {{cannot have template arguments}}
    289   template<typename T> A<T>::~A<T>() {}
    290 
    291   template<typename T> struct B { B(); ~B(); };
    292   template<typename T> B<T>::B() {}
    293   template<typename T> B<T>::~B() {}
    294 
    295   struct C { template<typename T> C(); C(); };
    296   template<typename T> C::C() {}
    297   C::C() {}
    298   template<> C::C<int>() {} // expected-error {{constructor name}} expected-error {{unqualified-id}}
    299   /*FIXME: needed for error recovery:*/;
    300 
    301   template<typename T> struct D { template<typename U> D(); D(); };
    302   template<typename T> D<T>::D() {} // expected-note {{previous}}
    303   template<typename T> template<typename U> D<T>::D() {}
    304   template<typename T> D<T>::D<T>() {} // expected-error {{redefinition}} expected-error {{cannot have template arg}}
    305 }
    306 
    307 namespace dr637 { // dr637: yes
    308   void f(int i) {
    309     i = ++i + 1;
    310     i = i++ + 1; // expected-warning {{unsequenced}}
    311   }
    312 }
    313 
    314 namespace dr638 { // dr638: no
    315   template<typename T> struct A {
    316     struct B;
    317     void f();
    318     void g();
    319     struct C {
    320       void h();
    321     };
    322   };
    323 
    324   class X {
    325     typedef int type;
    326     template<class T> friend struct A<T>::B; // expected-warning {{not supported}}
    327     template<class T> friend void A<T>::f(); // expected-warning {{not supported}}
    328     template<class T> friend void A<T>::g(); // expected-warning {{not supported}}
    329     template<class T> friend void A<T>::C::h(); // expected-warning {{not supported}}
    330   };
    331 
    332   template<> struct A<int> {
    333     X::type a; // FIXME: private
    334     struct B {
    335       X::type b; // ok
    336     };
    337     int f() { X::type c; } // FIXME: private
    338     void g() { X::type d; } // ok
    339     struct D {
    340       void h() { X::type e; } // FIXME: private
    341     };
    342   };
    343 }
    344 
    345 namespace dr639 { // dr639: yes
    346   void f(int i) {
    347     void((i = 0) + (i = 0)); // expected-warning {{unsequenced}}
    348   }
    349 }
    350