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