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