Home | History | Annotate | Download | only in Parser
      1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
      2 
      3 // New exciting ambiguities in C++11
      4 
      5 // final 'context sensitive' mess.
      6 namespace final {
      7   struct S { int n; };
      8   struct T { int n; };
      9   namespace N {
     10     int n;
     11     // These declare variables named final..
     12     extern struct S final;
     13     extern struct S final [[]];
     14     extern struct S final, foo;
     15     struct S final = S();
     16 
     17     // This defines a class, not a variable, even though it would successfully
     18     // parse as a variable but not as a class. DR1318's wording suggests that
     19     // this disambiguation is only performed on an ambiguity, but that was not
     20     // the intent.
     21     struct S final { // expected-note {{here}}
     22       int(n) // expected-error {{expected ';'}}
     23     };
     24     // This too.
     25     struct T final : S {}; // expected-error {{base 'S' is marked 'final'}}
     26     struct T bar : S {}; // expected-error {{expected ';' after top level declarator}} expected-error {{expected unqualified-id}}
     27   }
     28 }
     29 
     30 // enum versus bitfield mess.
     31 namespace bitfield {
     32   enum E {};
     33 
     34   struct T {
     35     constexpr T() {}
     36     constexpr T(int) {}
     37     constexpr T(T, T, T, T) {}
     38     constexpr T operator=(T) { return *this; }
     39     constexpr operator int() { return 4; }
     40   };
     41   constexpr T a, b, c, d;
     42 
     43   struct S1 {
     44     enum E : T ( a = 1, b = 2, c = 3, 4 ); // ok, declares a bitfield
     45   };
     46   // This could be a bit-field.
     47   struct S2 {
     48     enum E : T { a = 1, b = 2, c = 3, 4 }; // expected-error {{non-integral type}} expected-error {{expected '}'}} expected-note {{to match}}
     49   };
     50   struct S3 {
     51     enum E : int { a = 1, b = 2, c = 3, d }; // ok, defines an enum
     52   };
     53   // Ambiguous.
     54   struct S4 {
     55     enum E : int { a = 1 }; // ok, defines an enum
     56   };
     57   // This could be a bit-field, but would be ill-formed due to the anonymous
     58   // member being initialized.
     59   struct S5 {
     60     enum E : int { a = 1 } { b = 2 }; // expected-error {{expected ';' after enum}} expected-error {{expected member name}}
     61   };
     62   // This could be a bit-field.
     63   struct S6 {
     64     enum E : int { 1 }; // expected-error {{expected '}'}} expected-note {{to match}}
     65   };
     66 
     67   struct U {
     68     constexpr operator T() { return T(); } // expected-note 2{{candidate}}
     69   };
     70   // This could be a bit-field.
     71   struct S7 {
     72     enum E : int { a = U() }; // expected-error {{no viable conversion}}
     73   };
     74   // This could be a bit-field, and does not conform to the grammar of an
     75   // enum definition, because 'id(U())' is not a constant-expression.
     76   constexpr const U &id(const U &u) { return u; }
     77   struct S8 {
     78     enum E : int { a = id(U()) }; // expected-error {{no viable conversion}}
     79   };
     80 }
     81 
     82 namespace trailing_return {
     83   typedef int n;
     84   int a;
     85 
     86   struct S {
     87     S(int);
     88     S *operator()(...) const;
     89     int n;
     90   };
     91 
     92   namespace N {
     93     void f() {
     94       // This parses as a function declaration, but DR1223 makes the presence of
     95       // 'auto' be used for disambiguation.
     96       S(a)()->n; // ok, expression; expected-warning{{expression result unused}}
     97       S(a)(int())->n; // ok, expression; expected-warning{{expression result unused}}
     98       auto(a)()->n; // ok, function declaration
     99       auto(b)(int())->n; // ok, function declaration
    100       using T = decltype(a);
    101       using T = auto() -> n;
    102     }
    103   }
    104 }
    105 
    106 namespace ellipsis {
    107   template<typename...T>
    108   struct S {
    109     void e(S::S());
    110     void f(S(...args[sizeof(T)])); // expected-note {{here}}
    111     void f(S(...args)[sizeof(T)]); // expected-error {{redeclared}} expected-note {{here}}
    112     void f(S ...args[sizeof(T)]); // expected-error {{redeclared}}
    113     void g(S(...[sizeof(T)])); // expected-note {{here}}
    114     void g(S(...)[sizeof(T)]); // expected-error {{function cannot return array type}}
    115     void g(S ...[sizeof(T)]); // expected-error {{redeclared}}
    116     void h(T(...)); // function type, expected-error {{unexpanded parameter pack}}
    117     void h(T...); // pack expansion, ok
    118     void i(int(T...)); // expected-note {{here}}
    119     void i(int(T...a)); // expected-error {{redeclared}}
    120     void i(int(T, ...)); // function type, expected-error {{unexpanded parameter pack}}
    121     void i(int(T, ...a)); // expected-error {{expected ')'}} expected-note {{to match}} expected-error {{unexpanded parameter pack}}
    122     void j(int(int...)); // function type, ok
    123     void j(int(int...a)); // expected-error {{does not contain any unexpanded parameter packs}}
    124     void j(T(int...)); // expected-error {{unexpanded parameter pack}}
    125     void j(T(T...)); // expected-error {{unexpanded parameter pack}}
    126     void k(int(...)(T)); // expected-error {{cannot return function type}}
    127     void k(int ...(T));
    128   };
    129 }
    130