xref: /minix3/external/bsd/llvm/dist/clang/test/CXX/class.derived/class.abstract/p4.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc namespace PR6631 {
4*f4a2713aSLionel Sambuc   struct A {
5*f4a2713aSLionel Sambuc     virtual void f() = 0;
6*f4a2713aSLionel Sambuc   };
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc   struct B : virtual A { };
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc   struct C : virtual A {
11*f4a2713aSLionel Sambuc     virtual void f();
12*f4a2713aSLionel Sambuc   };
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc   struct D : public B, public C {
15*f4a2713aSLionel Sambuc     virtual void f();
16*f4a2713aSLionel Sambuc   };
17*f4a2713aSLionel Sambuc 
f()18*f4a2713aSLionel Sambuc   void f() {
19*f4a2713aSLionel Sambuc     (void)new D; // okay
20*f4a2713aSLionel Sambuc   }
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc // Check cases where we have a virtual function that is pure in one
24*f4a2713aSLionel Sambuc // subobject but not pure in another subobject.
25*f4a2713aSLionel Sambuc namespace PartlyPure {
26*f4a2713aSLionel Sambuc   struct A {
27*f4a2713aSLionel Sambuc     virtual void f() = 0; // expected-note{{unimplemented pure virtual method}}
28*f4a2713aSLionel Sambuc   };
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc   struct B : A {
31*f4a2713aSLionel Sambuc     virtual void f();
32*f4a2713aSLionel Sambuc   };
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc   struct C : virtual A { };
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc   struct D : B, C { };
37*f4a2713aSLionel Sambuc 
f()38*f4a2713aSLionel Sambuc   void f() {
39*f4a2713aSLionel Sambuc     (void) new D; // expected-error{{abstract class}}
40*f4a2713aSLionel Sambuc   }
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc namespace NonPureAlongOnePath {
44*f4a2713aSLionel Sambuc   struct A {
45*f4a2713aSLionel Sambuc     virtual void f() = 0;
46*f4a2713aSLionel Sambuc   };
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc   struct B : virtual A {
49*f4a2713aSLionel Sambuc     virtual void f();
50*f4a2713aSLionel Sambuc   };
51*f4a2713aSLionel Sambuc 
52*f4a2713aSLionel Sambuc   struct C : virtual A { };
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc   struct D : B, C { };
55*f4a2713aSLionel Sambuc 
f()56*f4a2713aSLionel Sambuc   void f() {
57*f4a2713aSLionel Sambuc     (void) new D; // okay
58*f4a2713aSLionel Sambuc   }
59*f4a2713aSLionel Sambuc }
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc namespace NonPureAlongOnePath2 {
62*f4a2713aSLionel Sambuc   struct Aprime {
63*f4a2713aSLionel Sambuc     virtual void f() = 0;
64*f4a2713aSLionel Sambuc   };
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc   struct A : Aprime {
67*f4a2713aSLionel Sambuc   };
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc   struct B : virtual A {
70*f4a2713aSLionel Sambuc     virtual void f();
71*f4a2713aSLionel Sambuc   };
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc   struct C : virtual A { };
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc   struct D : B, C { };
76*f4a2713aSLionel Sambuc 
f()77*f4a2713aSLionel Sambuc   void f() {
78*f4a2713aSLionel Sambuc     (void) new D; // okay
79*f4a2713aSLionel Sambuc   }
80*f4a2713aSLionel Sambuc }
81