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