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 | } |
Richard Smith | 150d853 | 2013-02-22 06:46:23 +0000 | [diff] [blame] | 28 | // _Alignas isn't allowed in the places where alignas is. We used to |
| 29 | // assert on this. |
| 30 | struct U final _Alignas(4) {}; // expected-error 3{{}} expected-note {{}} |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | // enum versus bitfield mess. |
| 34 | namespace bitfield { |
| 35 | enum E {}; |
| 36 | |
| 37 | struct T { |
| 38 | constexpr T() {} |
| 39 | constexpr T(int) {} |
| 40 | constexpr T(T, T, T, T) {} |
Richard Smith | 8404626 | 2013-04-21 01:08:50 +0000 | [diff] [blame] | 41 | constexpr T operator=(T) const { return *this; } |
| 42 | constexpr operator int() const { return 4; } |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 43 | }; |
| 44 | constexpr T a, b, c, d; |
| 45 | |
| 46 | struct S1 { |
| 47 | enum E : T ( a = 1, b = 2, c = 3, 4 ); // ok, declares a bitfield |
| 48 | }; |
| 49 | // This could be a bit-field. |
| 50 | struct S2 { |
| 51 | enum E : T { a = 1, b = 2, c = 3, 4 }; // expected-error {{non-integral type}} expected-error {{expected '}'}} expected-note {{to match}} |
| 52 | }; |
| 53 | struct S3 { |
| 54 | enum E : int { a = 1, b = 2, c = 3, d }; // ok, defines an enum |
| 55 | }; |
| 56 | // Ambiguous. |
| 57 | struct S4 { |
| 58 | enum E : int { a = 1 }; // ok, defines an enum |
| 59 | }; |
| 60 | // This could be a bit-field, but would be ill-formed due to the anonymous |
| 61 | // member being initialized. |
| 62 | struct S5 { |
Richard Smith | c9f3517 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 63 | enum E : int { a = 1 } { b = 2 }; // expected-error {{expected ';' after enum}} expected-error {{expected member name}} |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 64 | }; |
| 65 | // This could be a bit-field. |
| 66 | struct S6 { |
| 67 | enum E : int { 1 }; // expected-error {{expected '}'}} expected-note {{to match}} |
| 68 | }; |
| 69 | |
| 70 | struct U { |
Richard Smith | 8404626 | 2013-04-21 01:08:50 +0000 | [diff] [blame] | 71 | constexpr operator T() const { return T(); } // expected-note 2{{candidate}} |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 72 | }; |
| 73 | // This could be a bit-field. |
| 74 | struct S7 { |
| 75 | enum E : int { a = U() }; // expected-error {{no viable conversion}} |
| 76 | }; |
| 77 | // This could be a bit-field, and does not conform to the grammar of an |
| 78 | // enum definition, because 'id(U())' is not a constant-expression. |
| 79 | constexpr const U &id(const U &u) { return u; } |
| 80 | struct S8 { |
| 81 | enum E : int { a = id(U()) }; // expected-error {{no viable conversion}} |
| 82 | }; |
| 83 | } |
| 84 | |
| 85 | namespace trailing_return { |
| 86 | typedef int n; |
| 87 | int a; |
| 88 | |
| 89 | struct S { |
| 90 | S(int); |
Richard Smith | 5969a5f | 2012-07-23 21:41:30 +0000 | [diff] [blame] | 91 | S *operator()(...) const; |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 92 | int n; |
| 93 | }; |
| 94 | |
| 95 | namespace N { |
| 96 | void f() { |
| 97 | // This parses as a function declaration, but DR1223 makes the presence of |
| 98 | // 'auto' be used for disambiguation. |
| 99 | S(a)()->n; // ok, expression; expected-warning{{expression result unused}} |
Richard Smith | 5969a5f | 2012-07-23 21:41:30 +0000 | [diff] [blame] | 100 | S(a)(int())->n; // ok, expression; expected-warning{{expression result unused}} |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 101 | auto(a)()->n; // ok, function declaration |
Richard Smith | 5969a5f | 2012-07-23 21:41:30 +0000 | [diff] [blame] | 102 | auto(b)(int())->n; // ok, function declaration |
Richard Smith | d81e961 | 2012-02-23 01:36:12 +0000 | [diff] [blame] | 103 | using T = decltype(a); |
| 104 | using T = auto() -> n; |
| 105 | } |
| 106 | } |
| 107 | } |
Richard Smith | 2259286 | 2012-03-27 23:05:05 +0000 | [diff] [blame] | 108 | |
| 109 | namespace ellipsis { |
| 110 | template<typename...T> |
| 111 | struct S { |
| 112 | void e(S::S()); |
| 113 | void f(S(...args[sizeof(T)])); // expected-note {{here}} |
| 114 | void f(S(...args)[sizeof(T)]); // expected-error {{redeclared}} expected-note {{here}} |
| 115 | void f(S ...args[sizeof(T)]); // expected-error {{redeclared}} |
Richard Smith | 30f2a74 | 2013-02-20 20:19:27 +0000 | [diff] [blame] | 116 | void g(S(...[sizeof(T)])); // expected-note {{here}} expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}} |
Richard Smith | 2259286 | 2012-03-27 23:05:05 +0000 | [diff] [blame] | 117 | void g(S(...)[sizeof(T)]); // expected-error {{function cannot return array type}} |
| 118 | void g(S ...[sizeof(T)]); // expected-error {{redeclared}} |
| 119 | void h(T(...)); // function type, expected-error {{unexpanded parameter pack}} |
| 120 | void h(T...); // pack expansion, ok |
| 121 | void i(int(T...)); // expected-note {{here}} |
| 122 | void i(int(T...a)); // expected-error {{redeclared}} |
| 123 | void i(int(T, ...)); // function type, expected-error {{unexpanded parameter pack}} |
| 124 | void i(int(T, ...a)); // expected-error {{expected ')'}} expected-note {{to match}} expected-error {{unexpanded parameter pack}} |
| 125 | void j(int(int...)); // function type, ok |
| 126 | void j(int(int...a)); // expected-error {{does not contain any unexpanded parameter packs}} |
| 127 | void j(T(int...)); // expected-error {{unexpanded parameter pack}} |
| 128 | void j(T(T...)); // expected-error {{unexpanded parameter pack}} |
| 129 | void k(int(...)(T)); // expected-error {{cannot return function type}} |
| 130 | void k(int ...(T)); |
Richard Smith | 30f2a74 | 2013-02-20 20:19:27 +0000 | [diff] [blame] | 131 | void l(int(&...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}} |
| 132 | void l(int(*...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}} |
| 133 | void l(int(S<int>::*...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}} |
Richard Smith | 2259286 | 2012-03-27 23:05:05 +0000 | [diff] [blame] | 134 | }; |
| 135 | } |
Richard Smith | 576f32c | 2013-03-20 03:35:02 +0000 | [diff] [blame] | 136 | |
| 137 | namespace braced_init_list { |
| 138 | struct X { |
| 139 | void foo() {} |
| 140 | }; |
| 141 | |
| 142 | void (*pf1)() {}; |
| 143 | void (X::*pmf1)() {&X::foo}; |
| 144 | void (X::*pmf2)() = {&X::foo}; |
| 145 | |
| 146 | void test() { |
| 147 | void (*pf2)() {}; |
| 148 | void (X::*pmf3)() {&X::foo}; |
| 149 | void (X::*pmf4)() = {&X::foo}; |
| 150 | } |
| 151 | } |