abstract.cpp revision d1969d803cfcc65f1c334df4cc89c7fdd33ee4c9
1// RUN: clang-cc -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 e1[2]; // expected-error {{variable type 'C' is an abstract class}} 46C (*e2)[2]; // expected-error {{variable type 'C' is an abstract class}} 47C (**e3)[2]; // expected-error {{variable type 'C' is an abstract class}} 48 49void t4(C c[2]); // expected-error {{parameter type 'C' is an abstract class}} 50 51void t5(void (*)(C)); // expected-error {{parameter type 'C' is an abstract class}} 52 53typedef void (*Func)(C); // expected-error {{parameter type 'C' is an abstract class}} 54void t6(Func); 55 56class F { 57 F a() { while (1) {} } // expected-error {{return type 'F' is an abstract class}} 58 59 class D { 60 void f(F c); // expected-error {{parameter type 'F' is an abstract class}} 61 }; 62 63 union U { 64 void u(F c); // expected-error {{parameter type 'F' is an abstract class}} 65 }; 66 67 virtual void f() = 0; // expected-note {{pure virtual function 'f'}} 68}; 69 70class Abstract; 71 72void t7(Abstract a); // expected-error {{parameter type 'Abstract' is an abstract class}} 73 74void t8() { 75 void h(Abstract a); // expected-error {{parameter type 'Abstract' is an abstract class}} 76} 77 78namespace N { 79 void h(Abstract a); // expected-error {{parameter type 'Abstract' is an abstract class}} 80} 81 82class Abstract { 83 virtual void f() = 0; // expected-note {{pure virtual function 'f'}} 84}; 85 86// <rdar://problem/6854087> 87class foo { 88public: 89 virtual foo *getFoo() = 0; 90}; 91 92class bar : public foo { 93public: 94 virtual bar *getFoo(); 95}; 96 97bar x; 98 99// <rdar://problem/6902298> 100class A 101{ 102public: 103 virtual void release() = 0; 104 virtual void release(int count) = 0; 105 virtual void retain() = 0; 106}; 107 108class B : public A 109{ 110public: 111 virtual void release(); 112 virtual void release(int count); 113 virtual void retain(); 114}; 115 116void foo(void) 117{ 118 B b; 119} 120 121struct K { 122 int f; 123 virtual ~K(); 124}; 125 126struct L : public K { 127 void f(); 128}; 129