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