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
A(void)22 A(void){}
A(const A &)23 A(const A&){}
24
print(void)25 virtual void print(void) const { }
26 B compute(void) const;
27 };
28
29 class C {
30 public:
C()31 C() { }
C(C & o)32 C(C& o) { } // with it, things are wrong, without it, they're ok
beefy(void)33 virtual void beefy(void) const { printf("A::beefy\n"); exit(1); }
34 };
35
36 class B : private A, public C {
37 public:
B(const A & x,int)38 B(const A& x, int){}
beefy(void)39 void beefy(void) const { printf("B::beefy\n"); }
40 };
41
compute(void)42 B A::compute(void) const
43 {
44 B sub(*this, 1);
45 return sub;
46 }
47
main()48 int main ()
49 {
50 A titi;
51 titi.compute().beefy();
52 return 0;
53 }
54