1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wabstract-vbase-init
3 #ifndef __GXX_EXPERIMENTAL_CXX0X__
4 #define __CONCAT(__X, __Y) __CONCAT1(__X, __Y)
5 #define __CONCAT1(__X, __Y) __X ## __Y
7 #define static_assert(__b, __m) \
8 typedef int __CONCAT(__sa, __LINE__)[__b ? 1 : -1]
11 union IncompleteUnion
;
13 static_assert(!__is_abstract(IncompleteUnion
), "unions are never abstract");
16 virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f'}}
19 static_assert(__is_abstract(C
), "C has a pure virtual function");
24 static_assert(__is_abstract(D
), "D inherits from an abstract class");
30 static_assert(!__is_abstract(E
), "E inherits from an abstract class but implements f");
32 C
*d
= new C
; // expected-error {{allocating an object of abstract class type 'C'}}
34 C c
; // expected-error {{variable type 'C' is an abstract class}}
37 void t3(C c
){} // expected-error {{parameter type 'C' is an abstract class}}
38 void t4(C
){} // expected-error {{parameter type 'C' is an abstract class}}
41 C c
; // expected-error {{field type 'C' is an abstract class}}
47 C(); // expected-error {{allocating an object of abstract class type 'C'}}
48 t5(C()); // expected-error {{allocating an object of abstract class type 'C'}}
51 C e1
[2]; // expected-error {{array of abstract class type 'C'}}
52 C (*e2
)[2]; // expected-error {{array of abstract class type 'C'}}
53 C (**e3
)[2]; // expected-error {{array of abstract class type 'C'}}
55 void t6(C c
[2]); // expected-error {{array of abstract class type 'C'}}
59 typedef void (*Func
)(C
);
63 F
a() { while (1) {} } // expected-error {{return type 'F' is an abstract class}}
66 void f(F c
){} // expected-error {{parameter type 'F' is an abstract class}}
72 void u(F c
){} // expected-error {{parameter type 'F' is an abstract class}}
77 virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f'}}
80 // Diagnosing in these cases is prohibitively expensive. We still
81 // diagnose at the function definition, of course.
101 virtual foo
*getFoo() = 0;
104 class bar
: public foo
{
106 virtual bar
*getFoo();
113 virtual void release() = 0;
114 virtual void release(int count
) = 0;
115 virtual void retain() = 0;
120 virtual void release();
121 virtual void release(int count
);
122 virtual void retain();
134 struct L
: public K
{
141 virtual A
*clone() = 0;
143 struct B
: public A
{
144 virtual B
*clone() = 0;
146 struct C
: public B
{
153 // PR5550 - instantiating template didn't track overridden methods
156 virtual void a() = 0;
157 virtual void b() = 0;
159 template<typename T
> struct B
: public A
{
161 virtual void c() = 0;
163 struct C
: public B
<int> {
170 namespace PureImplicit
{
171 // A pure virtual destructor should be implicitly overridden.
172 struct A
{ virtual ~A() = 0; };
176 // A pure virtual assignment operator should be implicitly overridden.
178 struct C
{ virtual D
& operator=(const D
&) = 0; };
185 virtual void foo() = 0;
203 virtual void xfunc(void) = 0; // expected-note {{unimplemented pure virtual method}}
204 void g(X1 parm7
){} // expected-error {{parameter type 'X1' is an abstract class}}
205 void g(X1 parm8
[2]){} // expected-error {{parameter type 'X1' is an abstract class}}
210 virtual void xfunc(void) = 0; // expected-note {{unimplemented pure virtual method}}
211 void g(X2 parm10
){} // expected-error {{parameter type 'X2<N>' is an abstract class}}
212 void g(X2 parm11
[2]) {} // expected-error {{parameter type 'X2<N>' is an abstract class}}
217 struct A
{ // expected-note {{not complete until}}
218 A x
; // expected-error {{field has incomplete type}}
219 virtual void abstract() = 0;
222 struct B
{ // expected-note {{not complete until}}
223 virtual void abstract() = 0;
224 B x
; // expected-error {{field has incomplete type}}
228 static C x
; // expected-error {{abstract class}}
229 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
233 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
234 static D x
; // expected-error {{abstract class}}
239 template <class T
> struct A
{
240 A x
; // expected-error {{abstract class}}
241 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
244 template <class T
> struct B
{
245 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
246 B x
; // expected-error {{abstract class}}
249 template <class T
> struct C
{
250 static C x
; // expected-error {{abstract class}}
251 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
254 template <class T
> struct D
{
255 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
256 static D x
; // expected-error {{abstract class}}
261 struct A
{ A(int); virtual ~A() = 0; }; // expected-note {{pure virtual method}}
262 const A
&a
= 0; // expected-error {{abstract class}}
263 void f(const A
&a
= 0); // expected-error {{abstract class}}
265 void h() { g(0); } // expected-error {{abstract class}}
268 // PR9247: Crash on invalid in clang::Sema::ActOnFinishCXXMemberSpecification
271 virtual void g(const A
& input
) = 0;
282 virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f' in 'C'}}
285 void foo(const C
& c
) {}
288 foo(C(99)); // expected-error {{allocating an object of abstract class type 'C'}}
295 virtual void x() = 0; // expected-note {{unimplemented pure virtual method 'x' in 'RedundantInit'}}
297 struct B
: virtual A
{};
306 X
&operator=(const X
&);
308 struct Y
: virtual X
{ // expected-note {{class 'X' has an inaccessible copy assignment}}
311 struct Z
: Y
{}; // expected-note {{class 'Y' has a deleted copy assignment}}
312 void f(Z
&a
, const Z
&b
) { a
= b
; } // expected-error {{copy assignment operator is implicitly deleted}}
314 struct RedundantInit
: virtual A
{
315 RedundantInit() : A(0) {} // expected-warning {{initializer for virtual base class 'A' of abstract class 'RedundantInit' will never be used}}
319 struct inline_var
{ // expected-note {{until the closing '}'}}
320 static inline inline_var v
= 0; // expected-error {{incomplete type}} expected-warning {{extension}}
321 virtual void f() = 0;
324 struct var_template
{
326 static var_template v
; // expected-error {{abstract class}} expected-warning {{extension}}
327 virtual void f() = 0; // expected-note {{unimplemented}}
330 struct var_template_def
{ // expected-note {{until the closing '}'}}
332 static inline var_template_def v
= {}; // expected-error {{incomplete type}} expected-warning 2{{extension}}
333 virtual void f() = 0;
337 friend void g(friend_fn
);
338 virtual void f() = 0;
341 struct friend_fn_def
{
342 friend void g(friend_fn_def
) {} // expected-error {{abstract class}}
343 virtual void f() = 0; // expected-note {{unimplemented}}
346 struct friend_template
{
348 friend void g(friend_template
);
349 virtual void f() = 0;
352 struct friend_template_def
{
354 friend void g(friend_template_def
) {} // expected-error {{abstract class}}
355 virtual void f() = 0; // expected-note {{unimplemented}}
362 void f(foo
) = delete;
368 virtual void func() = 0; // expected-note {{unimplemented pure virtual method 'func' in 'S'}}
372 static_assert(__is_abstract(S
), "");
375 void func(S
) = delete;
377 void yet_another(S
) {} // expected-error{{parameter type 'S' is an abstract class}}