blob: 4c22ed3a9bbcd33511ad4f245266697fde2b3e65 [file] [log] [blame]
Richard Smithd81e9612012-02-23 01:36:12 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3// New exciting ambiguities in C++11
4
5// final 'context sensitive' mess.
6namespace final {
7 struct S { int n; };
Richard Smith7796eb52012-03-12 08:56:40 +00008 struct T { int n; };
Richard Smithd81e9612012-02-23 01:36:12 +00009 namespace N {
10 int n;
Richard Smith7796eb52012-03-12 08:56:40 +000011 // 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 Smithd81e9612012-02-23 01:36:12 +000017 // 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 Smith7796eb52012-03-12 08:56:40 +000021 struct S final { // expected-note {{here}}
Richard Smithd81e9612012-02-23 01:36:12 +000022 int(n) // expected-error {{expected ';'}}
23 };
Richard Smith7796eb52012-03-12 08:56:40 +000024 // This too.
25 struct T final : S {}; // expected-error {{base 'S' is marked 'final'}}
David Blaikie6f426692012-03-12 15:39:49 +000026 struct T bar : S {}; // expected-error {{expected ';' after top level declarator}} expected-error {{expected unqualified-id}}
Richard Smithd81e9612012-02-23 01:36:12 +000027 }
Richard Smith150d8532013-02-22 06:46:23 +000028 // _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 Smithd81e9612012-02-23 01:36:12 +000031}
32
33// enum versus bitfield mess.
34namespace bitfield {
35 enum E {};
36
37 struct T {
38 constexpr T() {}
39 constexpr T(int) {}
40 constexpr T(T, T, T, T) {}
Richard Smith84046262013-04-21 01:08:50 +000041 constexpr T operator=(T) const { return *this; }
42 constexpr operator int() const { return 4; }
Richard Smithd81e9612012-02-23 01:36:12 +000043 };
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 Smithc9f35172012-06-25 21:37:02 +000063 enum E : int { a = 1 } { b = 2 }; // expected-error {{expected ';' after enum}} expected-error {{expected member name}}
Richard Smithd81e9612012-02-23 01:36:12 +000064 };
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 Smith84046262013-04-21 01:08:50 +000071 constexpr operator T() const { return T(); } // expected-note 2{{candidate}}
Richard Smithd81e9612012-02-23 01:36:12 +000072 };
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
85namespace trailing_return {
86 typedef int n;
87 int a;
88
89 struct S {
90 S(int);
Richard Smith5969a5f2012-07-23 21:41:30 +000091 S *operator()(...) const;
Richard Smithd81e9612012-02-23 01:36:12 +000092 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 Smith5969a5f2012-07-23 21:41:30 +0000100 S(a)(int())->n; // ok, expression; expected-warning{{expression result unused}}
Richard Smithd81e9612012-02-23 01:36:12 +0000101 auto(a)()->n; // ok, function declaration
Richard Smith5969a5f2012-07-23 21:41:30 +0000102 auto(b)(int())->n; // ok, function declaration
Richard Smithd81e9612012-02-23 01:36:12 +0000103 using T = decltype(a);
104 using T = auto() -> n;
105 }
106 }
107}
Richard Smith22592862012-03-27 23:05:05 +0000108
109namespace 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 Smith30f2a742013-02-20 20:19:27 +0000116 void g(S(...[sizeof(T)])); // expected-note {{here}} expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
Richard Smith22592862012-03-27 23:05:05 +0000117 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 Smith30f2a742013-02-20 20:19:27 +0000131 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 Smith22592862012-03-27 23:05:05 +0000134 };
135}
Richard Smith576f32c2013-03-20 03:35:02 +0000136
137namespace 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}