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; }; |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 8 | struct T { int n; }; |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 9 | namespace N { |
| 10 | int n; |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 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 | |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 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. |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 21 | struct S final { // expected-note {{here}} |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 22 | int(n) // expected-error {{expected ';'}} |
| 23 | }; |
Richard Smith | 7796eb5 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 24 | // This too. |
| 25 | struct T final : S {}; // expected-error {{base 'S' is marked 'final'}} |
David Blaikie | 6f42669 | 2012-03-12 15:39:49 +0000 | [diff] [blame] | 26 | struct T bar : S {}; // expected-error {{expected ';' after top level declarator}} expected-error {{expected unqualified-id}} |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 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 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 | auto(a)()->n; // ok, function declaration |
| 98 | using T = decltype(a); |
| 99 | using T = auto() -> n; |
| 100 | } |
| 101 | } |
| 102 | } |
Richard Smith | 2259286 | 2012-03-27 23:05:05 +0000 | [diff] [blame] | 103 | |
| 104 | namespace ellipsis { |
| 105 | template<typename...T> |
| 106 | struct S { |
| 107 | void e(S::S()); |
| 108 | void f(S(...args[sizeof(T)])); // expected-note {{here}} |
| 109 | void f(S(...args)[sizeof(T)]); // expected-error {{redeclared}} expected-note {{here}} |
| 110 | void f(S ...args[sizeof(T)]); // expected-error {{redeclared}} |
| 111 | void g(S(...[sizeof(T)])); // expected-note {{here}} |
| 112 | void g(S(...)[sizeof(T)]); // expected-error {{function cannot return array type}} |
| 113 | void g(S ...[sizeof(T)]); // expected-error {{redeclared}} |
| 114 | void h(T(...)); // function type, expected-error {{unexpanded parameter pack}} |
| 115 | void h(T...); // pack expansion, ok |
| 116 | void i(int(T...)); // expected-note {{here}} |
| 117 | void i(int(T...a)); // expected-error {{redeclared}} |
| 118 | void i(int(T, ...)); // function type, expected-error {{unexpanded parameter pack}} |
| 119 | void i(int(T, ...a)); // expected-error {{expected ')'}} expected-note {{to match}} expected-error {{unexpanded parameter pack}} |
| 120 | void j(int(int...)); // function type, ok |
| 121 | void j(int(int...a)); // expected-error {{does not contain any unexpanded parameter packs}} |
| 122 | void j(T(int...)); // expected-error {{unexpanded parameter pack}} |
| 123 | void j(T(T...)); // expected-error {{unexpanded parameter pack}} |
| 124 | void k(int(...)(T)); // expected-error {{cannot return function type}} |
| 125 | void k(int ...(T)); |
| 126 | }; |
| 127 | } |