1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3 // New exciting ambiguities in C++11
5 // final 'context sensitive' mess.
11 // These declare variables named final..
12 extern struct S final
;
13 extern struct S final
[[]];
14 extern struct S final
, foo
;
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
21 struct S final
{ // expected-note {{here}}
22 int(n
) // expected-error {{expected ';'}}
25 struct T final
: S
{}; // expected-error {{base 'S' is marked 'final'}}
26 struct T bar
: S
{}; // expected-error {{expected ';' after top level declarator}} expected-error {{expected unqualified-id}}
28 // _Alignas isn't allowed in the places where alignas is. We used to
30 struct U final
_Alignas(4) {}; // expected-error 3{{}} expected-note {{}}
33 // enum versus bitfield. These are always required to be treated as an
34 // enum-base, but we disambiguate anyway for better error recovery.
41 constexpr T(T
, T
, T
, T
) {}
42 constexpr T
operator=(T
) const { return *this; }
43 constexpr operator int() const { return 4; }
45 constexpr T a
, b
, c
, d
;
48 enum E
: T ( a
= 1, b
= 2, c
= 3, 4 ); // expected-error {{ISO C++ only allows ':' in member enumeration declaration to introduce a fixed underlying type, not an anonymous bit-field}}
50 // Enum definition, not a bit-field.
52 enum E
: T
{ a
= 1, b
= 2, c
= 3, 4 }; // expected-error {{non-integral type}} expected-error {{expected identifier}}
55 enum E
: int { a
= 1, b
= 2, c
= 3, d
}; // ok, defines an enum
59 enum E
: int { a
= 1 }; // ok, defines an enum
61 // This could be a bit-field, but would be ill-formed due to the anonymous
62 // member being initialized.
64 enum E
: int { a
= 1 } { b
= 2 }; // expected-error {{expected ';' after enum}} expected-error {{expected member name}}
66 // This could be a bit-field.
68 enum E
: int { 1 }; // expected-error {{expected identifier}}
72 constexpr operator T() const { return T(); } // expected-note 2{{candidate}}
74 // This could be a bit-field.
76 enum E
: int { a
= U() }; // expected-error {{no viable conversion}}
78 // This could be a bit-field, and does not conform to the grammar of an
79 // enum definition, because 'id(U())' is not a constant-expression.
80 constexpr const U
&id(const U
&u
) { return u
; }
82 enum E
: int { a
= id(U()) }; // expected-error {{no viable conversion}}
85 // PR26249: Disambiguate 'enum :' as an enum-base always, even if that would
86 // be ill-formed. It cannot be an elaborated-type-specifier.
88 enum : undeclared_type
{ v
= 0 }; // expected-error {{unknown type name 'undeclared_type'}}
89 enum E
: undeclared_type
{ w
= 0 }; // expected-error {{unknown type name 'undeclared_type'}}
90 enum X
: undeclared_type
{ x
= 0 }; // expected-error {{unknown type name 'undeclared_type'}}
94 namespace trailing_return
{
100 S
*operator()(...) const;
106 // This parses as a function declaration, but DR1223 makes the presence of
107 // 'auto' be used for disambiguation.
108 S(a
)()->n
; // ok, expression; expected-warning{{expression result unused}}
109 S(a
)(int())->n
; // ok, expression; expected-warning{{expression result unused}}
110 auto(a
)()->n
; // ok, function declaration
111 auto(b
)(int())->n
; // ok, function declaration
112 using T
= decltype(a
);
113 using T
= auto() -> n
;
119 template<typename
...T
>
121 void e(S::S()); // expected-error {{is a constructor name}}
122 void f(S(...args
[sizeof(T
)])); // expected-note {{here}} expected-note {{here}}
123 void f(S(...args
)[sizeof(T
)]); // expected-error {{redeclared}}
124 void f(S
...args
[sizeof(T
)]); // expected-error {{redeclared}}
125 void g(S(...[sizeof(T
)])); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
126 void g(S(...)[sizeof(T
)]); // expected-error {{function cannot return array type}}
127 void h(T(...)); // function type, expected-error {{unexpanded parameter pack}}
128 void h(T
...); // pack expansion, ok
129 void i(int(T
...)); // expected-note {{here}}
130 void i(int(T
...a
)); // expected-error {{redeclared}}
131 void i(int(T
, ...)); // function type, expected-error {{unexpanded parameter pack}}
132 void i(int(T
, ...a
)); // expected-error {{expected ')'}} expected-note {{to match}} expected-error {{unexpanded parameter pack}}
133 void j(int(int...)); // function type, ok
134 void j(int(int...a
)); // expected-error {{does not contain any unexpanded parameter packs}}
135 void j(T(int...)); // expected-error {{unexpanded parameter pack}}
136 void j(T(T
...)); // expected-error {{unexpanded parameter pack}}
137 void k(int(...)(T
)); // expected-error {{cannot return function type}}
139 void l(int(&...)(T
)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
140 void l(int(*...)(T
)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
141 void l(int(S
<int>::*...)(T
)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
145 template <typename
...T
> constexpr CtorSink(T
&&...t
) { }
146 constexpr operator int() const { return 42; }
149 template <unsigned ...N
> struct UnsignedTmplArgSink
;
151 template <typename
...T
>
152 void foo(int x
, T
...t
) {
153 // Have a variety of cases where the syntax is technically unambiguous, but hinges on careful treatment of ellipses.
154 CtorSink(t
...), x
; // ok, expression; expected-warning 2{{expression result unused}}
156 int x0(CtorSink(t
...)); // ok, declares object x0
160 CtorSink
x1(int(t
) ..., int(x
)); // ok, declares object x1
164 UnsignedTmplArgSink
<T(CtorSink(t
...)) ...> *t0
; // ok
165 UnsignedTmplArgSink
<((T
*)0, 42u) ...> **t0p
= &t0
; // expected-warning 2{{left operand of comma operator has no effect}}
168 template void foo(int, int, int); // expected-note {{in instantiation of function template specialization 'ellipsis::foo<int, int>' requested here}}
171 namespace braced_init_list
{
177 void (X::*pmf1
)() {&X::foo
};
178 void (X::*pmf2
)() = {&X::foo
};
182 void (X::*pmf3
)() {&X::foo
};
183 void (X::*pmf4
)() = {&X::foo
};