[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Parser / cxx0x-ambig.cpp
blob7f3398ad1386c29b59ae20f1a92e78b94795f611
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3 // New exciting ambiguities in C++11
5 // final 'context sensitive' mess.
6 namespace final {
7 struct S { int n; };
8 struct T { int n; };
9 namespace N {
10 int n;
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();
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.
21 struct S final { // expected-note {{here}}
22 int(n) // expected-error {{expected ';'}}
24 // This too.
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
29 // assert on this.
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.
35 namespace bitfield {
36 enum E {};
38 struct T {
39 constexpr T() {}
40 constexpr T(int) {}
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;
47 struct S1 {
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.
51 struct S2 {
52 enum E : T { a = 1, b = 2, c = 3, 4 }; // expected-error {{non-integral type}} expected-error {{expected identifier}}
54 struct S3 {
55 enum E : int { a = 1, b = 2, c = 3, d }; // ok, defines an enum
57 // Ambiguous.
58 struct S4 {
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.
63 struct S5 {
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.
67 struct S6 {
68 enum E : int { 1 }; // expected-error {{expected identifier}}
71 struct U {
72 constexpr operator T() const { return T(); } // expected-note 2{{candidate}}
74 // This could be a bit-field.
75 struct S7 {
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; }
81 struct S8 {
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.
87 struct S {
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 {
95 typedef int n;
96 int a;
98 struct S {
99 S(int);
100 S *operator()(...) const;
101 int n;
104 namespace N {
105 void f() {
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;
118 namespace ellipsis {
119 template<typename...T>
120 struct S {
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-note {{here}} 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 g(S ...[sizeof(T)]); // expected-error {{redeclared}}
128 void h(T(...)); // function type, expected-error {{unexpanded parameter pack}}
129 void h(T...); // pack expansion, ok
130 void i(int(T...)); // expected-note {{here}}
131 void i(int(T...a)); // expected-error {{redeclared}}
132 void i(int(T, ...)); // function type, expected-error {{unexpanded parameter pack}}
133 void i(int(T, ...a)); // expected-error {{expected ')'}} expected-note {{to match}} expected-error {{unexpanded parameter pack}}
134 void j(int(int...)); // function type, ok
135 void j(int(int...a)); // expected-error {{does not contain any unexpanded parameter packs}}
136 void j(T(int...)); // expected-error {{unexpanded parameter pack}}
137 void j(T(T...)); // expected-error {{unexpanded parameter pack}}
138 void k(int(...)(T)); // expected-error {{cannot return function type}}
139 void k(int ...(T));
140 void l(int(&...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
141 void l(int(*...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
142 void l(int(S<int>::*...)(T)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
145 struct CtorSink {
146 template <typename ...T> constexpr CtorSink(T &&...t) { }
147 constexpr operator int() const { return 42; }
150 template <unsigned ...N> struct UnsignedTmplArgSink;
152 template <typename ...T>
153 void foo(int x, T ...t) {
154 // Have a variety of cases where the syntax is technically unambiguous, but hinges on careful treatment of ellipses.
155 CtorSink(t ...), x; // ok, expression; expected-warning 2{{expression result unused}}
157 int x0(CtorSink(t ...)); // ok, declares object x0
158 int *p0 = &x0;
159 (void)p0;
161 CtorSink x1(int(t) ..., int(x)); // ok, declares object x1
162 CtorSink *p1 = &x1;
163 (void)p1;
165 UnsignedTmplArgSink<T(CtorSink(t ...)) ...> *t0; // ok
166 UnsignedTmplArgSink<((T *)0, 42u) ...> **t0p = &t0; // expected-warning 2{{left operand of comma operator has no effect}}
169 template void foo(int, int, int); // expected-note {{in instantiation of function template specialization 'ellipsis::foo<int, int>' requested here}}
172 namespace braced_init_list {
173 struct X {
174 void foo() {}
177 void (*pf1)() {};
178 void (X::*pmf1)() {&X::foo};
179 void (X::*pmf2)() = {&X::foo};
181 void test() {
182 void (*pf2)() {};
183 void (X::*pmf3)() {&X::foo};
184 void (X::*pmf4)() = {&X::foo};