2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.mike / p2846b.C
blob57422fe64df21aeda233593a12508b058611fb50
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.
9 // Correct answer is B::beefy.
10 // g++ prints A::beefy, which is wrong.  Cfront gets it right.
12 // prms-id: 2846
14 extern "C" int printf(const char *, ...);
15 extern "C" void exit(int);
17 class B;
19 class A {
20  public:
22   A(void){}
23   A(const A&){}
25   virtual void print(void) const { }
26   B compute(void) const;
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); }
36 class B : private A, public C {
37 public:
38   B(const A& x, int){}
39   void beefy(void) const { printf("B::beefy\n"); }
42 B A::compute(void) const
44   B sub(*this, 1);
45   return sub;
48 int main ()
50   A titi;
51   titi.compute().beefy();
52   return 0;