Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 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 | namespace N { |
| 9 | int n; |
| 10 | // This defines a class, not a variable, even though it would successfully |
| 11 | // parse as a variable but not as a class. DR1318's wording suggests that |
| 12 | // this disambiguation is only performed on an ambiguity, but that was not |
| 13 | // the intent. |
| 14 | struct S final { |
| 15 | int(n) // expected-error {{expected ';'}} |
| 16 | }; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | // enum versus bitfield mess. |
| 21 | namespace bitfield { |
| 22 | enum E {}; |
| 23 | |
| 24 | struct T { |
| 25 | constexpr T() {} |
| 26 | constexpr T(int) {} |
| 27 | constexpr T(T, T, T, T) {} |
| 28 | constexpr T operator=(T) { return *this; } |
| 29 | constexpr operator int() { return 4; } |
| 30 | }; |
| 31 | constexpr T a, b, c, d; |
| 32 | |
| 33 | struct S1 { |
| 34 | enum E : T ( a = 1, b = 2, c = 3, 4 ); // ok, declares a bitfield |
| 35 | }; |
| 36 | // This could be a bit-field. |
| 37 | struct S2 { |
| 38 | enum E : T { a = 1, b = 2, c = 3, 4 }; // expected-error {{non-integral type}} expected-error {{expected '}'}} expected-note {{to match}} |
| 39 | }; |
| 40 | struct S3 { |
| 41 | enum E : int { a = 1, b = 2, c = 3, d }; // ok, defines an enum |
| 42 | }; |
| 43 | // Ambiguous. |
| 44 | struct S4 { |
| 45 | enum E : int { a = 1 }; // ok, defines an enum |
| 46 | }; |
| 47 | // This could be a bit-field, but would be ill-formed due to the anonymous |
| 48 | // member being initialized. |
| 49 | struct S5 { |
| 50 | enum E : int { a = 1 } { b = 2 }; // expected-error {{expected member name}} |
| 51 | }; |
| 52 | // This could be a bit-field. |
| 53 | struct S6 { |
| 54 | enum E : int { 1 }; // expected-error {{expected '}'}} expected-note {{to match}} |
| 55 | }; |
| 56 | |
| 57 | struct U { |
| 58 | constexpr operator T() { return T(); } // expected-note 2{{candidate}} |
| 59 | }; |
| 60 | // This could be a bit-field. |
| 61 | struct S7 { |
| 62 | enum E : int { a = U() }; // expected-error {{no viable conversion}} |
| 63 | }; |
| 64 | // This could be a bit-field, and does not conform to the grammar of an |
| 65 | // enum definition, because 'id(U())' is not a constant-expression. |
| 66 | constexpr const U &id(const U &u) { return u; } |
| 67 | struct S8 { |
| 68 | enum E : int { a = id(U()) }; // expected-error {{no viable conversion}} |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | namespace trailing_return { |
| 73 | typedef int n; |
| 74 | int a; |
| 75 | |
| 76 | struct S { |
| 77 | S(int); |
| 78 | S *operator()() const; |
| 79 | int n; |
| 80 | }; |
| 81 | |
| 82 | namespace N { |
| 83 | void f() { |
| 84 | // This parses as a function declaration, but DR1223 makes the presence of |
| 85 | // 'auto' be used for disambiguation. |
| 86 | S(a)()->n; // ok, expression; expected-warning{{expression result unused}} |
| 87 | auto(a)()->n; // ok, function declaration |
| 88 | using T = decltype(a); |
| 89 | using T = auto() -> n; |
| 90 | } |
| 91 | } |
| 92 | } |