blob: 9c8e2dc977465fad71cd2ade5814b17ae687c1c5 [file] [log] [blame]
Anders Carlsson67e4dd22009-03-22 01:52:17 +00001// 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 {
Anders Carlsson4681ebd2009-03-22 20:18:17 +000012 virtual void f() = 0; // expected-note {{pure virtual function 'f'}}
Anders Carlsson67e4dd22009-03-22 01:52:17 +000013};
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");
Anders Carlsson4681ebd2009-03-22 20:18:17 +000027
Anders Carlssonb9bbe492009-03-23 17:49:10 +000028C *d = new C; // expected-error {{allocation of an object of abstract type 'C'}}
29
Anders Carlsson4681ebd2009-03-22 20:18:17 +000030C 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};
Anders Carlssonb9bbe492009-03-23 17:49:10 +000037
Anders Carlsson11f21a02009-03-23 19:10:31 +000038void 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
Anders Carlsson8211eff2009-03-24 01:19:16 +000054class F {
55 F a() { } // expected-error {{return type 'F' is an abstract class}}
56
57 class D {
58 void f(F c); // expected-error {{parameter type 'F' is an abstract class}}
59 };
Anders Carlsson11f21a02009-03-23 19:10:31 +000060
Anders Carlsson8211eff2009-03-24 01:19:16 +000061 union U {
62 void u(F c); // expected-error {{parameter type 'F' is an abstract class}}
63 };
64
65 virtual void f() = 0; // expected-note {{pure virtual function 'f'}}
66};