1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s
2 class C;
3 class C {
4 public:
5 protected:
6   typedef int A,B;
7   static int sf(), u;
8 
9   struct S {};
10   enum {}; // expected-warning{{declaration does not declare anything}}
11   int; // expected-warning {{declaration does not declare anything}}
12   int : 1, : 2;
13 
14 public:
m0()15   void m0() {}; // ok, one extra ';' is permitted
m1()16   void m1() {}
17   ; // ok, one extra ';' is permitted
m()18   void m() {
19     int l = 2;
20   };; // expected-warning{{extra ';' after member function definition}}
21 
mt(T)22   template<typename T> void mt(T) { }
23   ;
24   ; // expected-warning{{extra ';' inside a class}}
25 
26   virtual int vf() const volatile = 0;
27 
28   virtual int vf0() = 0l; // expected-error {{does not look like a pure-specifier}}
29   virtual int vf1() = 1; // expected-error {{does not look like a pure-specifier}}
30   virtual int vf2() = 00; // expected-error {{does not look like a pure-specifier}}
31   virtual int vf3() = 0x0; // expected-error {{does not look like a pure-specifier}}
32   virtual int vf4() = 0.0; // expected-error {{does not look like a pure-specifier}}
vf5()33   virtual int vf5(){0}; // expected-error +{{}} expected-warning {{unused}}
vf5a()34   virtual int vf5a(){0;}; // function definition, expected-warning {{unused}}
35   virtual int vf6()(0); // expected-error +{{}} expected-note +{{}}
36   virtual int vf7() = { 0 }; // expected-error {{does not look like a pure-specifier}}
37 
38 private:
39   int x,f(),y,g();
40   inline int h();
41   static const int sci = 10;
42   mutable int mi;
43 };
glo()44 void glo()
45 {
46   struct local {};
47 }
48 
49 // PR3177
50 typedef union {
51   __extension__ union {
52     int a;
53     float b;
54   } y;
55 } bug3177;
56 
57 // check that we don't consume the token after the access specifier
58 // when it's not a colon
59 class D {
60 public // expected-error{{expected ':'}}
61   int i;
62 };
63 
64 // consume the token after the access specifier if it's a semicolon
65 // that was meant to be a colon
66 class E {
67 public; // expected-error{{expected ':'}}
68   int i;
69 };
70 
71 class F {
72     int F1 { return 1; } // expected-error{{function definition does not declare parameters}}
73     void F2 {} // expected-error{{function definition does not declare parameters}}
74     typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}}
F4()75     typedef void F4() {} // expected-error{{function definition declared 'typedef'}}
76 };
77 
78 namespace ctor_error {
79   class Foo {};
80   // By [class.qual]p2, this is a constructor declaration.
81   Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}}
82 
83   class Ctor { // expected-note{{not complete until the closing '}'}}
84     Ctor(f)(int); // ok
85     Ctor(g(int)); // ok
86     Ctor(x[5]); // expected-error{{incomplete type}}
87 
88     Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}}
89     void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}}
90   };
91 
92   Ctor::Ctor (x) = { 0 }; // \
93     // expected-error{{qualified reference to 'Ctor' is a constructor name}}
94 
Ctor(UnknownType *)95   Ctor::Ctor(UnknownType *) {} // \
96     // expected-error{{unknown type name 'UnknownType'}}
operator +(UnknownType *)97   void Ctor::operator+(UnknownType*) {} // \
98     // expected-error{{unknown type name 'UnknownType'}}
99 }
100 
101 namespace nns_decl {
102   struct A {
103     struct B;
104   };
105   namespace N {
106     union C;
107   }
108   struct A::B; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
109   union N::C; // expected-error {{forward declaration of union cannot have a nested name specifier}}
110 }
111 
112 // PR13775: Don't assert here.
113 namespace PR13775 {
114   class bar
115   {
116    public:
117     void foo ();
118     void baz ();
119   };
foo()120   void bar::foo ()
121   {
122     baz x(); // expected-error 3{{}}
123   }
124 }
125 
126 class pr16989 {
tpl_mem(int *)127   void tpl_mem(int *) {
128     return;
129     class C2 {
130       void f();
131     };
132     void C2::f() {} // expected-error{{function definition is not allowed here}}
133   };
134 };
135 
136 namespace CtorErrors {
137   struct A {
138     A(NonExistent); // expected-error {{unknown type name 'NonExistent'}}
139   };
140   struct B {
BCtorErrors::B141     B(NonExistent) : n(0) {} // expected-error {{unknown type name 'NonExistent'}}
142     int n;
143   };
144   struct C {
CCtorErrors::C145     C(NonExistent) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}}
146   };
147   struct D {
DCtorErrors::D148     D(NonExistent) {} // expected-error {{unknown type name 'NonExistent'}}
149   };
150 }
151 
152 namespace DtorErrors {
153   struct A { ~A(); int n; } a;
A()154   ~A::A() { n = 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}}
~A()155   A::~A() {} // expected-error {{redefinition}}
156 
157   struct B { ~B(); } *b;
B()158   DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
159 
f()160   void f() {
161     a.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}}
162     b->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}}
163   }
164 
165   struct C; // expected-note {{forward decl}}
C()166   ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
167 
168   struct D { struct X {}; ~D() throw(X); };
D()169   ~D::D() throw(X) {} // expected-error {{'~' in destructor name should be after nested name specifier}}
170 
Undeclared()171   ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
172   ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}}
173 
174   struct S {
175     // For another struct's destructor, emit the same diagnostic like for
176     // A::~A() in addition to the "~ in the wrong place" one.
A()177     ~A::A() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{non-friend class member '~A' cannot have a qualified name}}
~A()178     A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}}
179 
180     // An inline destructor with a redundant class name should also get the
181     // same diagnostic as S::~S.
S()182     ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
183 
184     // This just shouldn't crash.
185     int I; // expected-note {{declared here}}
I()186     ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
187   };
188 
189   struct T {};
190   T t1 = t1.T::~T<int>; // expected-error {{destructor name 'T' does not refer to a template}} expected-error {{expected '(' for function-style cast or type construction}} expected-error {{expected expression}}
191   // Emit the same diagnostic as for the previous case, plus something about ~.
192   T t2 = t2.~T::T<int>; // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{destructor name 'T' does not refer to a template}} expected-error {{expected '(' for function-style cast or type construction}} expected-error {{expected expression}}
193 }
194 
195 namespace BadFriend {
196   struct A {
197     friend int : 3; // expected-error {{friends can only be classes or functions}}
198     friend void f() = 123; // expected-error {{illegal initializer}}
199     friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}}
200     friend void f() final; // expected-error {{'final' is invalid in friend declarations}}
201     friend void f() override; // expected-error {{'override' is invalid in friend declarations}}
202   };
203 }
204 
205 class PR20760_a {
206   int a = ); // expected-warning {{extension}} expected-error {{expected expression}}
207   int b = }; // expected-warning {{extension}} expected-error {{expected expression}}
208   int c = ]; // expected-warning {{extension}} expected-error {{expected expression}}
209 };
210 class PR20760_b {
211   int d = d); // expected-warning {{extension}} expected-error {{expected ';'}}
212   int e = d]; // expected-warning {{extension}} expected-error {{expected ';'}}
213   int f = d // expected-warning {{extension}} expected-error {{expected ';'}}
214 };
215 
216 namespace PR20887 {
217 class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}}
218 class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}}
219 }
220 
221 class BadExceptionSpec {
222   void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}}
223   void g() throw(
224       int(
225           ; // expected-error {{unexpected ';' before ')'}}
226           ));
227 };
228 
229 // PR11109 must appear at the end of the source file
230 class pr11109r3 { // expected-note{{to match this '{'}}
231   public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}
232