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