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}}
35 void t1(C c
); // expected-error {{parameter type 'C' is an abstract class}}
36 void t2(C
); // expected-error {{parameter type 'C' is an abstract class}}
39 C c
; // expected-error {{field type 'C' is an abstract class}}
45 C(); // expected-error {{allocating an object of abstract class type 'C'}}
46 t3(C()); // expected-error {{allocating an object of abstract class type 'C'}}
49 C e1
[2]; // expected-error {{array of abstract class type 'C'}}
50 C (*e2
)[2]; // expected-error {{array of abstract class type 'C'}}
51 C (**e3
)[2]; // expected-error {{array of abstract class type 'C'}}
53 void t4(C c
[2]); // expected-error {{array of abstract class type 'C'}}
55 void t5(void (*)(C
)); // expected-error {{parameter type 'C' is an abstract class}}
57 typedef void (*Func
)(C
); // expected-error {{parameter type 'C' is an abstract class}}
61 F
a() { while (1) {} } // expected-error {{return type 'F' is an abstract class}}
64 void f(F c
); // expected-error {{parameter type 'F' is an abstract class}}
68 void u(F c
); // expected-error {{parameter type 'F' is an abstract class}}
71 virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f'}}
74 // Diagnosing in these cases is prohibitively expensive. We still
75 // diagnose at the function definition, of course.
93 // <rdar://problem/6854087>
96 virtual foo
*getFoo() = 0;
99 class bar
: public foo
{
101 virtual bar
*getFoo();
106 // <rdar://problem/6902298>
109 virtual void release() = 0;
110 virtual void release(int count
) = 0;
111 virtual void retain() = 0;
116 virtual void release();
117 virtual void release(int count
);
118 virtual void retain();
130 struct L
: public K
{
137 virtual A
*clone() = 0;
139 struct B
: public A
{
140 virtual B
*clone() = 0;
142 struct C
: public B
{
149 // PR5550 - instantiating template didn't track overridden methods
152 virtual void a() = 0;
153 virtual void b() = 0;
155 template<typename T
> struct B
: public A
{
157 virtual void c() = 0;
159 struct C
: public B
<int> {
166 namespace PureImplicit
{
167 // A pure virtual destructor should be implicitly overridden.
168 struct A
{ virtual ~A() = 0; };
172 // A pure virtual assignment operator should be implicitly overridden.
174 struct C
{ virtual D
& operator=(const D
&) = 0; };
181 virtual void foo() = 0;
197 // rdar://problem/8302168
200 virtual void xfunc(void) = 0; // expected-note {{unimplemented pure virtual method}}
201 void g(X1 parm7
); // expected-error {{parameter type 'test2::X1' is an abstract class}}
202 void g(X1 parm8
[2]); // expected-error {{array of abstract class type 'test2::X1'}}
207 virtual void xfunc(void) = 0; // expected-note {{unimplemented pure virtual method}}
208 void g(X2 parm10
); // expected-error {{parameter type 'X2<N>' is an abstract class}}
209 void g(X2 parm11
[2]); // expected-error {{array of abstract class type 'X2<N>'}}
214 struct A
{ // expected-note {{not complete until}}
215 A x
; // expected-error {{field has incomplete type}}
216 virtual void abstract() = 0;
219 struct B
{ // expected-note {{not complete until}}
220 virtual void abstract() = 0;
221 B x
; // expected-error {{field has incomplete type}}
225 static C x
; // expected-error {{abstract class}}
226 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
230 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
231 static D x
; // expected-error {{abstract class}}
236 template <class T
> struct A
{
237 A x
; // expected-error {{abstract class}}
238 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
241 template <class T
> struct B
{
242 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
243 B x
; // expected-error {{abstract class}}
246 template <class T
> struct C
{
247 static C x
; // expected-error {{abstract class}}
248 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
251 template <class T
> struct D
{
252 virtual void abstract() = 0; // expected-note {{unimplemented pure virtual method}}
253 static D x
; // expected-error {{abstract class}}
258 struct A
{ A(int); virtual ~A() = 0; }; // expected-note {{pure virtual method}}
259 const A
&a
= 0; // expected-error {{abstract class}}
260 void f(const A
&a
= 0); // expected-error {{abstract class}}
262 void h() { g(0); } // expected-error {{abstract class}}
265 // PR9247: Crash on invalid in clang::Sema::ActOnFinishCXXMemberSpecification
268 virtual void g(const A
& input
) = 0;
279 virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f' in 'C'}}
282 void foo(const C
& c
) {}
285 foo(C(99)); // expected-error {{allocating an object of abstract class type 'C'}}
292 virtual void x() = 0; // expected-note {{unimplemented pure virtual method 'x' in 'RedundantInit'}}
294 struct B
: virtual A
{};
303 X
&operator=(const X
&);
305 struct Y
: virtual X
{ // expected-note {{class 'X' has an inaccessible copy assignment}}
308 struct Z
: Y
{}; // expected-note {{class 'Y' has a deleted copy assignment}}
309 void f(Z
&a
, const Z
&b
) { a
= b
; } // expected-error {{copy assignment operator is implicitly deleted}}
311 struct RedundantInit
: virtual A
{
312 RedundantInit() : A(0) {} // expected-warning {{initializer for virtual base class 'A' of abstract class 'RedundantInit' will never be used}}
316 struct inline_var
{ // expected-note {{until the closing '}'}}
317 static inline inline_var v
= 0; // expected-error {{incomplete type}} expected-warning {{extension}}
318 virtual void f() = 0;
321 struct var_template
{
323 static var_template v
; // expected-error {{abstract class}} expected-warning {{extension}}
324 virtual void f() = 0; // expected-note {{unimplemented}}
327 struct var_template_def
{ // expected-note {{until the closing '}'}}
329 static inline var_template_def v
= {}; // expected-error {{incomplete type}} expected-warning 2{{extension}}
330 virtual void f() = 0;
334 friend void g(friend_fn
); // expected-error {{abstract class}}
335 virtual void f() = 0; // expected-note {{unimplemented}}
338 struct friend_fn_def
{
339 friend void g(friend_fn_def
) {} // expected-error {{abstract class}}
340 virtual void f() = 0; // expected-note {{unimplemented}}
343 struct friend_template
{
345 friend void g(friend_template
); // expected-error {{abstract class}}
346 virtual void f() = 0; // expected-note {{unimplemented}}
349 struct friend_template_def
{
351 friend void g(friend_template_def
) {} // expected-error {{abstract class}}
352 virtual void f() = 0; // expected-note {{unimplemented}}