blob: d4cbfeab75d80e609ab382330995dbc0e9312a64 [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 }
28}
29
30// enum versus bitfield mess.
31namespace bitfield {
32 enum E {};
33
34 struct T {
35 constexpr T() {}
36 constexpr T(int) {}
37 constexpr T(T, T, T, T) {}
38 constexpr T operator=(T) { return *this; }
39 constexpr operator int() { return 4; }
40 };
41 constexpr T a, b, c, d;
42
43 struct S1 {
44 enum E : T ( a = 1, b = 2, c = 3, 4 ); // ok, declares a bitfield
45 };
46 // This could be a bit-field.
47 struct S2 {
48 enum E : T { a = 1, b = 2, c = 3, 4 }; // expected-error {{non-integral type}} expected-error {{expected '}'}} expected-note {{to match}}
49 };
50 struct S3 {
51 enum E : int { a = 1, b = 2, c = 3, d }; // ok, defines an enum
52 };
53 // Ambiguous.
54 struct S4 {
55 enum E : int { a = 1 }; // ok, defines an enum
56 };
57 // This could be a bit-field, but would be ill-formed due to the anonymous
58 // member being initialized.
59 struct S5 {
60 enum E : int { a = 1 } { b = 2 }; // expected-error {{expected member name}}
61 };
62 // This could be a bit-field.
63 struct S6 {
64 enum E : int { 1 }; // expected-error {{expected '}'}} expected-note {{to match}}
65 };
66
67 struct U {
68 constexpr operator T() { return T(); } // expected-note 2{{candidate}}
69 };
70 // This could be a bit-field.
71 struct S7 {
72 enum E : int { a = U() }; // expected-error {{no viable conversion}}
73 };
74 // This could be a bit-field, and does not conform to the grammar of an
75 // enum definition, because 'id(U())' is not a constant-expression.
76 constexpr const U &id(const U &u) { return u; }
77 struct S8 {
78 enum E : int { a = id(U()) }; // expected-error {{no viable conversion}}
79 };
80}
81
82namespace trailing_return {
83 typedef int n;
84 int a;
85
86 struct S {
87 S(int);
88 S *operator()() const;
89 int n;
90 };
91
92 namespace N {
93 void f() {
94 // This parses as a function declaration, but DR1223 makes the presence of
95 // 'auto' be used for disambiguation.
96 S(a)()->n; // ok, expression; expected-warning{{expression result unused}}
97 auto(a)()->n; // ok, function declaration
98 using T = decltype(a);
99 using T = auto() -> n;
100 }
101 }
102}