xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/recovery.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -verify -std=c++11 %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc 8gi///===--- recovery.cpp ---===// // expected-error {{unqualified-id}}
4f4a2713aSLionel Sambuc namespace Std { // expected-note {{here}}
5f4a2713aSLionel Sambuc   typedef int Important;
6f4a2713aSLionel Sambuc }
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc / redeclare as an inline namespace // expected-error {{unqualified-id}}
9f4a2713aSLionel Sambuc inline namespace Std { // expected-error {{cannot be reopened as inline}}
10f4a2713aSLionel Sambuc   Important n;
11f4a2713aSLionel Sambuc } / end namespace Std // expected-error {{unqualified-id}}
12f4a2713aSLionel Sambuc int x;
13f4a2713aSLionel Sambuc Std::Important y;
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc extenr "C" { // expected-error {{did you mean 'extern'}}
16f4a2713aSLionel Sambuc   void f();
17f4a2713aSLionel Sambuc }
g()18f4a2713aSLionel Sambuc void g() {
19f4a2713aSLionel Sambuc   z = 1; // expected-error {{undeclared}}
20f4a2713aSLionel Sambuc   f();
21f4a2713aSLionel Sambuc }
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc struct S {
24f4a2713aSLionel Sambuc   int a, b, c;
25f4a2713aSLionel Sambuc   S();
26f4a2713aSLionel Sambuc   int x // expected-error {{expected ';'}}
27f4a2713aSLionel Sambuc   friend void f()
28f4a2713aSLionel Sambuc };
S()29f4a2713aSLionel Sambuc 8S::S() : a{ 5 }, b{ 6 }, c{ 2 } { // expected-error {{unqualified-id}}
30f4a2713aSLionel Sambuc   return;
31f4a2713aSLionel Sambuc }
32f4a2713aSLionel Sambuc int k;
33f4a2713aSLionel Sambuc int l = k // expected-error {{expected ';'}}
34f4a2713aSLionel Sambuc constexpr int foo();
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc 5int m = { l }, n = m; // expected-error {{unqualified-id}}
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc namespace MissingBrace {
39f4a2713aSLionel Sambuc   struct S { // expected-error {{missing '}' at end of definition of 'MissingBrace::S'}}
40f4a2713aSLionel Sambuc     int f();
41f4a2713aSLionel Sambuc   // };
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc   namespace N { int g(); } // expected-note {{still within definition of 'MissingBrace::S' here}}
44f4a2713aSLionel Sambuc 
45f4a2713aSLionel Sambuc   int k1 = S().h(); // expected-error {{no member named 'h' in 'MissingBrace::S'}}
46f4a2713aSLionel Sambuc   int k2 = S().f() + N::g();
47f4a2713aSLionel Sambuc 
48f4a2713aSLionel Sambuc   template<typename T> struct PR17949 { // expected-error {{missing '}' at end of definition of 'MissingBrace::PR17949'}}
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc   namespace X { // expected-note {{still within definition of 'MissingBrace::PR17949' here}}
51f4a2713aSLionel Sambuc   }
52f4a2713aSLionel Sambuc }
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc namespace N {
55f4a2713aSLionel Sambuc   int
56f4a2713aSLionel Sambuc } // expected-error {{unqualified-id}}
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc strcut Uuuu { // expected-error {{did you mean 'struct'}} \
59f4a2713aSLionel Sambuc               // expected-note {{'Uuuu' declared here}}
60f4a2713aSLionel Sambuc } *u[3];
61f4a2713aSLionel Sambuc uuuu v; // expected-error {{did you mean 'Uuuu'}}
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc struct Redefined { // expected-note {{previous}}
64f4a2713aSLionel Sambuc   Redefined() {}
65f4a2713aSLionel Sambuc };
66f4a2713aSLionel Sambuc struct Redefined { // expected-error {{redefinition}}
67f4a2713aSLionel Sambuc   Redefined() {}
68f4a2713aSLionel Sambuc };
69f4a2713aSLionel Sambuc 
70f4a2713aSLionel Sambuc struct MissingSemi5;
71f4a2713aSLionel Sambuc namespace N {
72f4a2713aSLionel Sambuc   typedef int afterMissingSemi4;
73f4a2713aSLionel Sambuc   extern MissingSemi5 afterMissingSemi5;
74f4a2713aSLionel Sambuc }
75f4a2713aSLionel Sambuc 
76f4a2713aSLionel Sambuc struct MissingSemi1 {} // expected-error {{expected ';' after struct}}
77f4a2713aSLionel Sambuc static int afterMissingSemi1();
78f4a2713aSLionel Sambuc 
79f4a2713aSLionel Sambuc class MissingSemi2 {} // expected-error {{expected ';' after class}}
80f4a2713aSLionel Sambuc MissingSemi1 *afterMissingSemi2;
81f4a2713aSLionel Sambuc 
82f4a2713aSLionel Sambuc enum MissingSemi3 {} // expected-error {{expected ';' after enum}}
83f4a2713aSLionel Sambuc ::MissingSemi1 afterMissingSemi3;
84f4a2713aSLionel Sambuc 
85f4a2713aSLionel Sambuc extern N::afterMissingSemi4 afterMissingSemi4b;
86f4a2713aSLionel Sambuc union MissingSemi4 { MissingSemi4(int); } // expected-error {{expected ';' after union}}
87f4a2713aSLionel Sambuc N::afterMissingSemi4 (afterMissingSemi4b);
88f4a2713aSLionel Sambuc 
89f4a2713aSLionel Sambuc int afterMissingSemi5b;
90f4a2713aSLionel Sambuc struct MissingSemi5 { MissingSemi5(int); } // ok, no missing ';' here
91f4a2713aSLionel Sambuc N::afterMissingSemi5 (afterMissingSemi5b);
92f4a2713aSLionel Sambuc 
93f4a2713aSLionel Sambuc template<typename T> struct MissingSemiT {
94f4a2713aSLionel Sambuc } // expected-error {{expected ';' after struct}}
95f4a2713aSLionel Sambuc MissingSemiT<int> msi;
96f4a2713aSLionel Sambuc 
97f4a2713aSLionel Sambuc struct MissingSemiInStruct {
98f4a2713aSLionel Sambuc   struct Inner1 {} // expected-error {{expected ';' after struct}}
99f4a2713aSLionel Sambuc   static MissingSemi5 ms1;
100f4a2713aSLionel Sambuc 
101f4a2713aSLionel Sambuc   struct Inner2 {} // ok, no missing ';' here
102f4a2713aSLionel Sambuc   static MissingSemi1;
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc   struct Inner3 {} // expected-error {{expected ';' after struct}}
105f4a2713aSLionel Sambuc   static MissingSemi5 *p;
106f4a2713aSLionel Sambuc };
107f4a2713aSLionel Sambuc 
108f4a2713aSLionel Sambuc void MissingSemiInFunction() {
109f4a2713aSLionel Sambuc   struct Inner1 {} // expected-error {{expected ';' after struct}}
110f4a2713aSLionel Sambuc   if (true) {}
111f4a2713aSLionel Sambuc 
112f4a2713aSLionel Sambuc   // FIXME: It would be nice to at least warn on this.
113f4a2713aSLionel Sambuc   struct Inner2 { Inner2(int); } // ok, no missing ';' here
114f4a2713aSLionel Sambuc   k = l;
115f4a2713aSLionel Sambuc 
116f4a2713aSLionel Sambuc   struct Inner3 {} // expected-error {{expected ';' after struct}}
117f4a2713aSLionel Sambuc   Inner1 i1;
118f4a2713aSLionel Sambuc 
119f4a2713aSLionel Sambuc   struct Inner4 {} // ok, no missing ';' here
120f4a2713aSLionel Sambuc   Inner5;
121f4a2713aSLionel Sambuc }
122*0a6a1f1dSLionel Sambuc 
123*0a6a1f1dSLionel Sambuc namespace NS {
124*0a6a1f1dSLionel Sambuc   template<typename T> struct Foo {};
125*0a6a1f1dSLionel Sambuc }
126*0a6a1f1dSLionel Sambuc struct MissingSemiThenTemplate1 {} // expected-error {{expected ';' after struct}}
127*0a6a1f1dSLionel Sambuc NS::Foo<int> missingSemiBeforeFunctionReturningTemplateId1();
128*0a6a1f1dSLionel Sambuc 
129*0a6a1f1dSLionel Sambuc using NS::Foo;
130*0a6a1f1dSLionel Sambuc struct MissingSemiThenTemplate2 {} // expected-error {{expected ';' after struct}}
131*0a6a1f1dSLionel Sambuc Foo<int> missingSemiBeforeFunctionReturningTemplateId2();
132*0a6a1f1dSLionel Sambuc 
133*0a6a1f1dSLionel Sambuc namespace PR17084 {
134*0a6a1f1dSLionel Sambuc enum class EnumID {};
135*0a6a1f1dSLionel Sambuc template <typename> struct TempID;
136*0a6a1f1dSLionel Sambuc template <> struct TempID<BadType> : BadType, EnumID::Garbage; // expected-error{{use of undeclared identifier 'BadType'}}
137*0a6a1f1dSLionel Sambuc }
138*0a6a1f1dSLionel Sambuc 
139*0a6a1f1dSLionel Sambuc namespace pr15133 {
140*0a6a1f1dSLionel Sambuc   namespace ns {
141*0a6a1f1dSLionel Sambuc     const int V1 = 1;   // expected-note {{declared here}}
142*0a6a1f1dSLionel Sambuc   }
143*0a6a1f1dSLionel Sambuc   struct C1 {
144*0a6a1f1dSLionel Sambuc     enum E1 { V2 = 2 }; // expected-note {{declared here}}
145*0a6a1f1dSLionel Sambuc     static const int V3 = 3; // expected-note {{declared here}}
146*0a6a1f1dSLionel Sambuc   };
147*0a6a1f1dSLionel Sambuc   enum E2 {
148*0a6a1f1dSLionel Sambuc     V4 = 4,   // expected-note {{declared here}}
149*0a6a1f1dSLionel Sambuc     V6        // expected-note {{declared here}}
150*0a6a1f1dSLionel Sambuc   };
151*0a6a1f1dSLionel Sambuc   enum class EC3 { V0 = 0, V5 = 5 }; // expected-note {{declared here}}
152*0a6a1f1dSLionel Sambuc   void func_3();
153*0a6a1f1dSLionel Sambuc 
154*0a6a1f1dSLionel Sambuc   void func_1(int x) {
155*0a6a1f1dSLionel Sambuc     switch(x) {
156*0a6a1f1dSLionel Sambuc     case 0: break;
157*0a6a1f1dSLionel Sambuc     case ns::V1:: break; // expected-error{{'V1' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
158*0a6a1f1dSLionel Sambuc     case C1::V2:: break; // expected-error{{'V2' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
159*0a6a1f1dSLionel Sambuc     case C1::V3:: break; // expected-error{{'V3' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
160*0a6a1f1dSLionel Sambuc     case V4:: break; // expected-error{{'V4' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
161*0a6a1f1dSLionel Sambuc     case V6:: func_3();   // expected-error{{'V6' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
162*0a6a1f1dSLionel Sambuc     }
163*0a6a1f1dSLionel Sambuc   }
164*0a6a1f1dSLionel Sambuc   void func_2(EC3 x) {
165*0a6a1f1dSLionel Sambuc     switch(x) {
166*0a6a1f1dSLionel Sambuc     case EC3::V0:  break;
167*0a6a1f1dSLionel Sambuc     case EC3::V5:: break; // expected-error{{'V5' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
168*0a6a1f1dSLionel Sambuc     }
169*0a6a1f1dSLionel Sambuc   }
170*0a6a1f1dSLionel Sambuc 
171*0a6a1f1dSLionel Sambuc   template<class T> struct TS1 {
172*0a6a1f1dSLionel Sambuc     typedef int A;
173*0a6a1f1dSLionel Sambuc   };
174*0a6a1f1dSLionel Sambuc   template<class T> void func(int x) {
175*0a6a1f1dSLionel Sambuc     switch(x) {
176*0a6a1f1dSLionel Sambuc     case TS1<T>::A:: break;  // expected-error{{expected unqualified-id}}
177*0a6a1f1dSLionel Sambuc     }
178*0a6a1f1dSLionel Sambuc   };
179*0a6a1f1dSLionel Sambuc   void mainf() {
180*0a6a1f1dSLionel Sambuc     func<int>(1);
181*0a6a1f1dSLionel Sambuc   }
182*0a6a1f1dSLionel Sambuc 
183*0a6a1f1dSLionel Sambuc   struct S {
184*0a6a1f1dSLionel Sambuc     static int n;  // expected-note{{declared here}}
185*0a6a1f1dSLionel Sambuc     int nn;        // expected-note 2 {{declared here}}
186*0a6a1f1dSLionel Sambuc   };
187*0a6a1f1dSLionel Sambuc 
188*0a6a1f1dSLionel Sambuc   int func_3(int x) {
189*0a6a1f1dSLionel Sambuc     return x ? S::n :: 0;  // expected-error{{'n' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
190*0a6a1f1dSLionel Sambuc   }
191*0a6a1f1dSLionel Sambuc   int func_4(int x, S &s) {
192*0a6a1f1dSLionel Sambuc     return x ? s.nn :: x;  // expected-error{{'nn' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
193*0a6a1f1dSLionel Sambuc   }
194*0a6a1f1dSLionel Sambuc   int func_5(int x, S &s) {
195*0a6a1f1dSLionel Sambuc     return x ? s.nn :: S::n;  // expected-error{{'nn' cannot appear before '::' because it is not a class, namespace, or scoped enumeration; did you mean ':'?}}
196*0a6a1f1dSLionel Sambuc   }
197*0a6a1f1dSLionel Sambuc 
198*0a6a1f1dSLionel Sambuc   struct S2 {
199*0a6a1f1dSLionel Sambuc     struct S3;
200*0a6a1f1dSLionel Sambuc   };
201*0a6a1f1dSLionel Sambuc 
202*0a6a1f1dSLionel Sambuc   struct S2 :: S3 :: public S2 {  // expected-error{{'public' cannot be a part of nested name specifier; did you mean ':'?}}
203*0a6a1f1dSLionel Sambuc   };
204*0a6a1f1dSLionel Sambuc }
205