summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/inherit/covariant17.C
blob: b2de15f7ed6b1da27c500f3ca3fe33333f53c124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// PR c++/43120
// { dg-do run }

extern "C" void abort ();

struct A {
  int a;

  A(int a_) : a(a_) {}

  A(const A &other) { }

  virtual void dummy() {}
};

struct B {
  virtual B *clone() const = 0;
};

struct C : public virtual B {
  virtual C *clone() const = 0;
};

struct E* ep;
struct E : public A, public C {
  E(int a_) : A(a_) { ep = this; }

  virtual E *clone() const {
    if (this != ep)
      abort();
    return 0;
  }
};

int main() {
  E *a = new E(123);
  C *c = a;
  B *b = a;
  c->clone();
  b->clone();
  delete a;
  return 0;
}