blob: 2d5b518c691fe3317d9167ca62579097935a3795 [file] [log] [blame]
Stephen Hines0e2c34f2015-03-23 12:09:02 -07001// RUN: %clang_cc1 -verify -std=c++11 -fms-extensions %s
Richard Smith994d73f2012-04-11 20:59:20 +00002
38gi///===--- recovery.cpp ---===// // expected-error {{unqualified-id}}
4namespace Std { // expected-note {{here}}
5 typedef int Important;
6}
7
8/ redeclare as an inline namespace // expected-error {{unqualified-id}}
9inline namespace Std { // expected-error {{cannot be reopened as inline}}
10 Important n;
11} / end namespace Std // expected-error {{unqualified-id}}
12int x;
13Std::Important y;
14
Richard Smith2d670972013-08-17 00:46:16 +000015extenr "C" { // expected-error {{did you mean 'extern'}}
Richard Smith994d73f2012-04-11 20:59:20 +000016 void f();
17}
18void g() {
19 z = 1; // expected-error {{undeclared}}
Kaelyn Uhrain50dc12a2012-06-15 23:45:58 +000020 f();
Richard Smith994d73f2012-04-11 20:59:20 +000021}
22
23struct S {
24 int a, b, c;
25 S();
Richard Smith53aec2a2012-10-25 00:00:53 +000026 int x // expected-error {{expected ';'}}
27 friend void f()
Richard Smith994d73f2012-04-11 20:59:20 +000028};
298S::S() : a{ 5 }, b{ 6 }, c{ 2 } { // expected-error {{unqualified-id}}
30 return;
31}
32int k;
Richard Smith53aec2a2012-10-25 00:00:53 +000033int l = k // expected-error {{expected ';'}}
34constexpr int foo();
Richard Smith994d73f2012-04-11 20:59:20 +000035
365int m = { l }, n = m; // expected-error {{unqualified-id}}
37
Richard Smithb3104392013-11-09 04:52:51 +000038namespace MissingBrace {
39 struct S { // expected-error {{missing '}' at end of definition of 'MissingBrace::S'}}
40 int f();
41 // };
42
43 namespace N { int g(); } // expected-note {{still within definition of 'MissingBrace::S' here}}
44
45 int k1 = S().h(); // expected-error {{no member named 'h' in 'MissingBrace::S'}}
46 int k2 = S().f() + N::g();
Richard Smith7faf81f2013-11-15 23:00:02 +000047
48 template<typename T> struct PR17949 { // expected-error {{missing '}' at end of definition of 'MissingBrace::PR17949'}}
49
50 namespace X { // expected-note {{still within definition of 'MissingBrace::PR17949' here}}
51 }
Richard Smithb3104392013-11-09 04:52:51 +000052}
53
Richard Smith994d73f2012-04-11 20:59:20 +000054namespace N {
55 int
56} // expected-error {{unqualified-id}}
57
Richard Smith2d670972013-08-17 00:46:16 +000058strcut Uuuu { // expected-error {{did you mean 'struct'}} \
Kaelyn Uhrain50dc12a2012-06-15 23:45:58 +000059 // expected-note {{'Uuuu' declared here}}
60} *u[3];
61uuuu v; // expected-error {{did you mean 'Uuuu'}}
Richard Smith37ec8d52012-12-05 11:34:06 +000062
63struct Redefined { // expected-note {{previous}}
64 Redefined() {}
65};
66struct Redefined { // expected-error {{redefinition}}
67 Redefined() {}
68};
Bill Wendlingf0cc19f2013-11-19 22:56:43 +000069
70struct MissingSemi5;
71namespace N {
72 typedef int afterMissingSemi4;
73 extern MissingSemi5 afterMissingSemi5;
74}
75
76struct MissingSemi1 {} // expected-error {{expected ';' after struct}}
77static int afterMissingSemi1();
78
79class MissingSemi2 {} // expected-error {{expected ';' after class}}
80MissingSemi1 *afterMissingSemi2;
81
82enum MissingSemi3 {} // expected-error {{expected ';' after enum}}
83::MissingSemi1 afterMissingSemi3;
84
85extern N::afterMissingSemi4 afterMissingSemi4b;
86union MissingSemi4 { MissingSemi4(int); } // expected-error {{expected ';' after union}}
87N::afterMissingSemi4 (afterMissingSemi4b);
88
89int afterMissingSemi5b;
90struct MissingSemi5 { MissingSemi5(int); } // ok, no missing ';' here
91N::afterMissingSemi5 (afterMissingSemi5b);
92
93template<typename T> struct MissingSemiT {
94} // expected-error {{expected ';' after struct}}
95MissingSemiT<int> msi;
96
97struct MissingSemiInStruct {
98 struct Inner1 {} // expected-error {{expected ';' after struct}}
99 static MissingSemi5 ms1;
100
101 struct Inner2 {} // ok, no missing ';' here
102 static MissingSemi1;
103
104 struct Inner3 {} // expected-error {{expected ';' after struct}}
105 static MissingSemi5 *p;
106};
107
108void MissingSemiInFunction() {
109 struct Inner1 {} // expected-error {{expected ';' after struct}}
110 if (true) {}
111
112 // FIXME: It would be nice to at least warn on this.
113 struct Inner2 { Inner2(int); } // ok, no missing ';' here
114 k = l;
115
116 struct Inner3 {} // expected-error {{expected ';' after struct}}
117 Inner1 i1;
118
119 struct Inner4 {} // ok, no missing ';' here
120 Inner5;
121}
Bill Wendlinge78e8fc2013-12-23 10:02:34 +0000122
Stephen Hines651f13c2014-04-23 16:59:28 -0700123namespace NS {
124 template<typename T> struct Foo {};
125}
126struct MissingSemiThenTemplate1 {} // expected-error {{expected ';' after struct}}
127NS::Foo<int> missingSemiBeforeFunctionReturningTemplateId1();
128
129using NS::Foo;
130struct MissingSemiThenTemplate2 {} // expected-error {{expected ';' after struct}}
131Foo<int> missingSemiBeforeFunctionReturningTemplateId2();
132
Bill Wendlinge78e8fc2013-12-23 10:02:34 +0000133namespace PR17084 {
134enum class EnumID {};
135template <typename> struct TempID;
136template <> struct TempID<BadType> : BadType, EnumID::Garbage; // expected-error{{use of undeclared identifier 'BadType'}}
137}
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700138
139namespace pr15133 {
140 namespace ns {
141 const int V1 = 1; // expected-note {{declared here}}
142 }
143 struct C1 {
144 enum E1 { V2 = 2 }; // expected-note {{declared here}}
145 static const int V3 = 3; // expected-note {{declared here}}
146 };
147 enum E2 {
148 V4 = 4, // expected-note {{declared here}}
149 V6 // expected-note {{declared here}}
150 };
151 enum class EC3 { V0 = 0, V5 = 5 }; // expected-note {{declared here}}
152 void func_3();
153
154 void func_1(int x) {
155 switch(x) {
156 case 0: break;
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700157 case ns::V1:: break; // expected-error{{'V1' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
158 case C1::V2:: break; // expected-error{{'V2' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
159 case C1::V3:: break; // expected-error{{'V3' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
160 case V4:: break; // expected-error{{'V4' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
161 case V6:: func_3(); // expected-error{{'V6' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700162 }
163 }
164 void func_2(EC3 x) {
165 switch(x) {
166 case EC3::V0: break;
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700167 case EC3::V5:: break; // expected-error{{'V5' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700168 }
169 }
170
171 template<class T> struct TS1 {
172 typedef int A;
173 };
174 template<class T> void func(int x) {
175 switch(x) {
176 case TS1<T>::A:: break; // expected-error{{expected unqualified-id}}
177 }
178 };
179 void mainf() {
180 func<int>(1);
181 }
182
183 struct S {
184 static int n; // expected-note{{declared here}}
185 int nn; // expected-note 2 {{declared here}}
186 };
187
188 int func_3(int x) {
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700189 return x ? S::n :: 0; // expected-error{{'n' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700190 }
191 int func_4(int x, S &s) {
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700192 return x ? s.nn :: x; // expected-error{{'nn' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700193 }
194 int func_5(int x, S &s) {
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700195 return x ? s.nn :: S::n; // expected-error{{'nn' cannot appear before '::' because it is not a class, namespace, or enumeration; did you mean ':'?}}
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700196 }
197
198 struct S2 {
199 struct S3;
200 };
201
202 struct S2 :: S3 :: public S2 { // expected-error{{'public' cannot be a part of nested name specifier; did you mean ':'?}}
203 };
204}
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700205
206namespace InvalidEmptyNames {
207// These shouldn't crash, the diagnostics aren't important.
208struct ::, struct ::; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
209enum ::, enum ::; // expected-error 2 {{expected identifier}} expected-warning {{declaration does not declare anything}}
210struct ::__super, struct ::__super; // expected-error 2 {{expected identifier}} expected-error 2 {{expected '::' after '__super'}}
211struct ::template foo, struct ::template bar; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
212struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}} expected-error {{declaration of anonymous struct must be a definition}}
213class :: : {} a; // expected-error {{expected identifier}} expected-error {{expected class name}}
214}