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