abstract.cpp revision a165da09c0313309d2d4dda42d0b2d4096a372a1
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 {
79void 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 {
101public:
102  virtual void release() = 0;
103  virtual void release(int count) = 0;
104  virtual void retain() = 0;
105};
106
107class B : public A {
108public:
109  virtual void release();
110  virtual void release(int count);
111  virtual void retain();
112};
113
114void foo(void) {
115  B b;
116}
117
118struct K {
119 int f;
120 virtual ~K();
121};
122
123struct L : public K {
124 void f();
125};
126
127// PR5222
128namespace PR5222 {
129  struct A {
130    virtual A *clone() = 0;
131  };
132  struct B : public A {
133    virtual B *clone() = 0;
134  };
135  struct C : public B {
136    virtual C *clone();
137  };
138
139  C c;
140}
141
142// PR5550 - instantiating template didn't track overridden methods
143namespace PR5550 {
144  struct A {
145    virtual void a() = 0;
146    virtual void b() = 0;
147  };
148  template<typename T> struct B : public A {
149    virtual void b();
150    virtual void c() = 0;
151  };
152  struct C : public B<int> {
153    virtual void a();
154    virtual void c();
155  };
156  C x;
157}
158