xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/recovery.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -verify -std=c++11 %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc 8gi///===--- recovery.cpp ---===// // expected-error {{unqualified-id}}
4*f4a2713aSLionel Sambuc namespace Std { // expected-note {{here}}
5*f4a2713aSLionel Sambuc   typedef int Important;
6*f4a2713aSLionel Sambuc }
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc / redeclare as an inline namespace // expected-error {{unqualified-id}}
9*f4a2713aSLionel Sambuc inline namespace Std { // expected-error {{cannot be reopened as inline}}
10*f4a2713aSLionel Sambuc   Important n;
11*f4a2713aSLionel Sambuc } / end namespace Std // expected-error {{unqualified-id}}
12*f4a2713aSLionel Sambuc int x;
13*f4a2713aSLionel Sambuc Std::Important y;
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc extenr "C" { // expected-error {{did you mean 'extern'}}
16*f4a2713aSLionel Sambuc   void f();
17*f4a2713aSLionel Sambuc }
18*f4a2713aSLionel Sambuc void g() {
19*f4a2713aSLionel Sambuc   z = 1; // expected-error {{undeclared}}
20*f4a2713aSLionel Sambuc   f();
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc struct S {
24*f4a2713aSLionel Sambuc   int a, b, c;
25*f4a2713aSLionel Sambuc   S();
26*f4a2713aSLionel Sambuc   int x // expected-error {{expected ';'}}
27*f4a2713aSLionel Sambuc   friend void f()
28*f4a2713aSLionel Sambuc };
29*f4a2713aSLionel Sambuc 8S::S() : a{ 5 }, b{ 6 }, c{ 2 } { // expected-error {{unqualified-id}}
30*f4a2713aSLionel Sambuc   return;
31*f4a2713aSLionel Sambuc }
32*f4a2713aSLionel Sambuc int k;
33*f4a2713aSLionel Sambuc int l = k // expected-error {{expected ';'}}
34*f4a2713aSLionel Sambuc constexpr int foo();
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc 5int m = { l }, n = m; // expected-error {{unqualified-id}}
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc namespace MissingBrace {
39*f4a2713aSLionel Sambuc   struct S { // expected-error {{missing '}' at end of definition of 'MissingBrace::S'}}
40*f4a2713aSLionel Sambuc     int f();
41*f4a2713aSLionel Sambuc   // };
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc   namespace N { int g(); } // expected-note {{still within definition of 'MissingBrace::S' here}}
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc   int k1 = S().h(); // expected-error {{no member named 'h' in 'MissingBrace::S'}}
46*f4a2713aSLionel Sambuc   int k2 = S().f() + N::g();
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc   template<typename T> struct PR17949 { // expected-error {{missing '}' at end of definition of 'MissingBrace::PR17949'}}
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc   namespace X { // expected-note {{still within definition of 'MissingBrace::PR17949' here}}
51*f4a2713aSLionel Sambuc   }
52*f4a2713aSLionel Sambuc }
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc namespace N {
55*f4a2713aSLionel Sambuc   int
56*f4a2713aSLionel Sambuc } // expected-error {{unqualified-id}}
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc strcut Uuuu { // expected-error {{did you mean 'struct'}} \
59*f4a2713aSLionel Sambuc               // expected-note {{'Uuuu' declared here}}
60*f4a2713aSLionel Sambuc } *u[3];
61*f4a2713aSLionel Sambuc uuuu v; // expected-error {{did you mean 'Uuuu'}}
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc struct Redefined { // expected-note {{previous}}
64*f4a2713aSLionel Sambuc   Redefined() {}
65*f4a2713aSLionel Sambuc };
66*f4a2713aSLionel Sambuc struct Redefined { // expected-error {{redefinition}}
67*f4a2713aSLionel Sambuc   Redefined() {}
68*f4a2713aSLionel Sambuc };
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc struct MissingSemi5;
71*f4a2713aSLionel Sambuc namespace N {
72*f4a2713aSLionel Sambuc   typedef int afterMissingSemi4;
73*f4a2713aSLionel Sambuc   extern MissingSemi5 afterMissingSemi5;
74*f4a2713aSLionel Sambuc }
75*f4a2713aSLionel Sambuc 
76*f4a2713aSLionel Sambuc struct MissingSemi1 {} // expected-error {{expected ';' after struct}}
77*f4a2713aSLionel Sambuc static int afterMissingSemi1();
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc class MissingSemi2 {} // expected-error {{expected ';' after class}}
80*f4a2713aSLionel Sambuc MissingSemi1 *afterMissingSemi2;
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc enum MissingSemi3 {} // expected-error {{expected ';' after enum}}
83*f4a2713aSLionel Sambuc ::MissingSemi1 afterMissingSemi3;
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc extern N::afterMissingSemi4 afterMissingSemi4b;
86*f4a2713aSLionel Sambuc union MissingSemi4 { MissingSemi4(int); } // expected-error {{expected ';' after union}}
87*f4a2713aSLionel Sambuc N::afterMissingSemi4 (afterMissingSemi4b);
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc int afterMissingSemi5b;
90*f4a2713aSLionel Sambuc struct MissingSemi5 { MissingSemi5(int); } // ok, no missing ';' here
91*f4a2713aSLionel Sambuc N::afterMissingSemi5 (afterMissingSemi5b);
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc template<typename T> struct MissingSemiT {
94*f4a2713aSLionel Sambuc } // expected-error {{expected ';' after struct}}
95*f4a2713aSLionel Sambuc MissingSemiT<int> msi;
96*f4a2713aSLionel Sambuc 
97*f4a2713aSLionel Sambuc struct MissingSemiInStruct {
98*f4a2713aSLionel Sambuc   struct Inner1 {} // expected-error {{expected ';' after struct}}
99*f4a2713aSLionel Sambuc   static MissingSemi5 ms1;
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc   struct Inner2 {} // ok, no missing ';' here
102*f4a2713aSLionel Sambuc   static MissingSemi1;
103*f4a2713aSLionel Sambuc 
104*f4a2713aSLionel Sambuc   struct Inner3 {} // expected-error {{expected ';' after struct}}
105*f4a2713aSLionel Sambuc   static MissingSemi5 *p;
106*f4a2713aSLionel Sambuc };
107*f4a2713aSLionel Sambuc 
108*f4a2713aSLionel Sambuc void MissingSemiInFunction() {
109*f4a2713aSLionel Sambuc   struct Inner1 {} // expected-error {{expected ';' after struct}}
110*f4a2713aSLionel Sambuc   if (true) {}
111*f4a2713aSLionel Sambuc 
112*f4a2713aSLionel Sambuc   // FIXME: It would be nice to at least warn on this.
113*f4a2713aSLionel Sambuc   struct Inner2 { Inner2(int); } // ok, no missing ';' here
114*f4a2713aSLionel Sambuc   k = l;
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc   struct Inner3 {} // expected-error {{expected ';' after struct}}
117*f4a2713aSLionel Sambuc   Inner1 i1;
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc   struct Inner4 {} // ok, no missing ';' here
120*f4a2713aSLionel Sambuc   Inner5;
121*f4a2713aSLionel Sambuc }
122