abstract.cpp revision 11f21a08cd40caec93e088c404bbf3136917a035
1// RUN: clang -fsyntax-only -verify %s -std=c++0x
2
3#ifndef __GXX_EXPERIMENTAL_CXX0X__
4#define __CONCAT(__X, __Y) __CONCAT1(__X, __Y)
5#define __CONCAT1(__X, __Y) __X ## __Y
6
7#define static_assert(__b, __m) \
8  typedef int __CONCAT(__sa, __LINE__)[__b ? 1 : -1]
9#endif
10
11class C {
12    virtual void f() = 0; // expected-note {{pure virtual function 'f'}}
13};
14
15static_assert(__is_abstract(C), "C has a pure virtual function");
16
17class D : C {
18};
19
20static_assert(__is_abstract(D), "D inherits from an abstract class");
21
22class E : D {
23    virtual void f();
24};
25
26static_assert(!__is_abstract(E), "E inherits from an abstract class but implements f");
27
28C *d = new C; // expected-error {{allocation of an object of abstract type 'C'}}
29
30C c; // expected-error {{variable type 'C' is an abstract class}}
31void t1(C c); // expected-error {{parameter type 'C' is an abstract class}}
32void t2(C); // expected-error {{parameter type 'C' is an abstract class}}
33
34struct S {
35  C c; // expected-error {{field type 'C' is an abstract class}}
36};
37
38void t3(const C&);
39
40void f() {
41    C(); // expected-error {{allocation of an object of abstract type 'C'}}
42    t3(C()); // expected-error {{allocation of an object of abstract type 'C'}}
43}
44
45C e[2]; // expected-error {{variable type 'C' is an abstract class}}
46
47void t4(C c[2]); // expected-error {{parameter type 'C' is an abstract class}}
48
49void t5(void (*)(C)); // expected-error {{parameter type 'C' is an abstract class}}
50
51typedef void (*Func)(C); // expected-error {{parameter type 'C' is an abstract class}}
52void t6(Func);
53
54
55