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 14extern "C" int printf(const char *, ...); 15extern "C" void exit(int); 16 17class B; 18 19class 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 29class C { 30public: 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 36class B : private A, public C { 37public: 38 B(const A& x, int){} 39 void beefy(void) const { printf("B::beefy\n"); } 40}; 41 42B A::compute(void) const 43{ 44 B sub(*this, 1); 45 return sub; 46} 47 48int main () 49{ 50 A titi; 51 titi.compute().beefy(); 52 return 0; 53} 54