OSDN Git Service

Merge in xfails from PR14107.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.mike / p2846b.C
1 // { dg-do run  }
2 // Shows that problem of initializing one object's secondary base from
3 // another object via a user defined copy constructor for that base,
4 // the pointer for the secondary vtable is not set after implicit
5 // copying of the outer class, but rather has the pointer to the main
6 // vtable for the secondary base left over from the user defined copy
7 // constructor for that base.
8
9 // Correct answer is B::beefy.
10 // g++ prints A::beefy, which is wrong.  Cfront gets it right.
11
12 // prms-id: 2846
13
14 extern "C" int printf(const char *, ...);
15 extern "C" void exit(int);
16
17 class B;
18
19 class A {
20  public:
21
22   A(void){}
23   A(const A&){}
24
25   virtual void print(void) const { }
26   B compute(void) const;
27 };
28
29 class C {
30 public:
31   C() { }
32   C(C& o) { }           // with it, things are wrong, without it, they're ok
33   virtual void beefy(void) const { printf("A::beefy\n"); exit(1); }
34 };
35
36 class B : private A, public C {
37 public:
38   B(const A& x, int){}
39   void beefy(void) const { printf("B::beefy\n"); }
40 };
41
42 B A::compute(void) const
43 {
44   B sub(*this, 1);
45   return sub;
46 }
47
48 int main ()
49 {
50   A titi;
51   titi.compute().beefy();
52   return 0;
53 }