Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / Parser / cxx-class.cpp
bloba6757f39146a16980f0766a8fecc0e09403fca66
1 // RUN: %clang_cc1 -std=c++14 -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
5 class C;
6 class C {
7 public:
8 protected:
9 typedef int A,B;
10 static int sf(), u;
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;
17 public:
18 void m0() {}; // ok, one extra ';' is permitted
19 void m1() {}
20 ; // ok, one extra ';' is permitted
21 void m() {
22 int l = 2;
23 };; // expected-warning{{extra ';' after member function definition}}
25 template<typename T> void mt(T) { }
27 ; // expected-warning{{extra ';' inside a class}}
29 virtual int vf() const volatile = 0;
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}}
36 virtual int vf5(){0}; // expected-error +{{}} expected-warning {{unused}}
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 virtual int PR45267() = \
41 0; // ok, despite escaped newline
43 private:
44 int x,f(),y,g();
45 inline int h();
46 static const int sci = 10;
47 mutable int mi;
49 void glo()
51 struct local {};
54 // PR3177
55 typedef union {
56 __extension__ union {
57 int a;
58 float b;
59 } y;
60 } bug3177;
62 // check that we don't consume the token after the access specifier
63 // when it's not a colon
64 class D {
65 public // expected-error{{expected ':'}}
66 int i;
69 // consume the token after the access specifier if it's a semicolon
70 // that was meant to be a colon
71 class E {
72 public; // expected-error{{expected ':'}}
73 int i;
76 class F {
77 int F1 { return 1; }
78 #if __cplusplus <= 199711L
79 // expected-error@-2 {{function definition does not declare parameters}}
80 #else
81 // expected-error@-4 {{expected expression}}
82 // expected-error@-5 {{expected}}
83 // expected-note@-6 {{to match this '{'}}
84 // expected-error@-7 {{expected ';' after class}}
85 #endif
87 void F2 {}
88 #if __cplusplus <= 199711L
89 // expected-error@-2 {{function definition does not declare parameters}}
90 #else
91 // expected-error@-4 {{variable has incomplete type 'void'}}
92 // expected-error@-5 {{expected ';' after top level declarator}}
93 #endif
95 typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}}
96 typedef void F4() {} // expected-error{{function definition declared 'typedef'}}
98 #if __cplusplus >= 201103L
99 // expected-error@-2 {{extraneous closing brace}}
100 #endif
102 namespace ctor_error {
103 class Foo {}; // #defined-here
104 // By [class.qual]p2, this is a constructor declaration.
105 Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}}
106 // expected-note@#defined-here{{defined here}}
108 class Ctor { // expected-note{{not complete until the closing '}'}}
109 Ctor(f)(int); // ok
110 Ctor(g(int)); // ok
111 Ctor(x[5]); // expected-error{{incomplete type}}
113 Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}}
114 void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}}
117 Ctor::Ctor (x) = { 0 }; // \
118 // expected-error{{qualified reference to 'Ctor' is a constructor name}}
120 Ctor::Ctor(UnknownType *) {} // \
121 // expected-error{{unknown type name 'UnknownType'}}
122 void Ctor::operator+(UnknownType*) {} // \
123 // expected-error{{unknown type name 'UnknownType'}}
126 namespace nns_decl {
127 struct A {
128 struct B;
130 namespace N {
131 union C;
133 struct A::B; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
134 union N::C; // expected-error {{forward declaration of union cannot have a nested name specifier}}
137 // PR13775: Don't assert here.
138 namespace PR13775 {
139 class bar
141 public:
142 void foo ();
143 void baz ();
145 void bar::foo ()
147 baz x(); // expected-error 3{{}}
151 class pr16989 {
152 void tpl_mem(int *) {
153 return;
154 class C2 {
155 void f();
157 void C2::f() {} // expected-error{{function definition is not allowed here}}
161 namespace CtorErrors {
162 struct A {
163 A(NonExistent); // expected-error {{unknown type name 'NonExistent'}}
165 struct B {
166 B(NonExistent) : n(0) {} // expected-error {{unknown type name 'NonExistent'}}
167 int n;
169 struct C {
170 C(NonExistent) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}}
172 struct D {
173 D(NonExistent) {} // expected-error {{unknown type name 'NonExistent'}}
177 namespace DtorErrors {
178 struct A { ~A(); int n; } a;
179 ~A::A() { n = 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}}
180 A::~A() {} // expected-error {{redefinition}}
182 struct B { ~B(); } *b;
183 DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
185 void f() {
186 a.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}}
187 b->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}}
190 struct C; // expected-note {{forward decl}}
191 ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
193 struct D { struct X {}; ~D() throw(X); };
194 ~D::D() throw(X) {} // expected-error {{'~' in destructor name should be after nested name specifier}}
196 ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
197 ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}}
199 struct S {
200 // For another struct's destructor, emit the same diagnostic like for
201 // A::~A() in addition to the "~ in the wrong place" one.
202 ~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}}
203 A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}}
205 // An inline destructor with a redundant class name should also get the
206 // same diagnostic as S::~S.
207 ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
209 // This just shouldn't crash.
210 int I; // expected-note {{declared here}}
211 ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
214 struct T {};
215 T t1 = t1.T::~T<int>; // expected-error {{destructor name 'T' does not refer to a template}}
216 // Emit the same diagnostic as for the previous case, plus something about ~.
217 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}}
220 namespace BadFriend {
221 struct A {
222 friend int : 3; // expected-error {{friends can only be classes or functions}}
223 friend void f() = 123; // expected-error {{illegal initializer}}
224 friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}}
225 friend void f() final; // expected-error {{'final' is invalid in friend declarations}}
226 friend void f() override; // expected-error {{'override' is invalid in friend declarations}}
230 class PR20760_a {
231 int a = ); // expected-error {{expected expression}}
232 #if __cplusplus <= 199711L
233 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
234 #endif
236 int b = }; // expected-error {{expected expression}}
237 #if __cplusplus <= 199711L
238 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
239 #endif
241 int c = ]; // expected-error {{expected expression}}
242 #if __cplusplus <= 199711L
243 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
244 #endif
247 class PR20760_b {
248 int d = d); // expected-error {{expected ';'}}
249 #if __cplusplus <= 199711L
250 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
251 #endif
253 int e = d]; // expected-error {{expected ';'}}
254 #if __cplusplus <= 199711L
255 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
256 #endif
258 int f = d // expected-error {{expected ';'}}
259 #if __cplusplus <= 199711L
260 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
261 #endif
265 namespace PR20887 {
266 class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}}
267 class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}}
270 class BadExceptionSpec {
271 void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}}
272 void g() throw(
273 int(
274 ; // expected-error {{unexpected ';' before ')'}}
278 namespace PR41192 {
279 extern struct A a;
280 struct A {} ::PR41192::a; // ok, no missing ';' here expected-warning {{extra qualification}}
282 #if __cplusplus >= 201103L
283 struct C;
284 struct D { static C c; };
285 struct C {} decltype(D())::c; // expected-error {{a 'decltype' specifier cannot be used in a declarative nested name specifier}}
286 #endif
289 namespace ArrayMemberAccess {
290 struct A {
291 int x;
292 template<typename T> int f() const;
294 void f(const A (&a)[]) {
295 // OK: not a template-id.
296 bool cond = a->x < 10 && a->x > 0;
297 // OK: a template-id.
298 a->f<int>();
302 namespace UndeclaredBaseTemplate {
303 template<class> struct imp;
304 template<class T> struct is_member_function_pointer : undeclared<imp<T>::member> {}; // expected-error {{unknown template name 'undeclared'}}
307 // PR11109 must appear at the end of the source file
308 class pr11109r3 { // expected-note{{to match this '{'}}
309 public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}