1 // { dg-do run  }
2 // Shows that problem of initializing one object's vtable pointer from
3 // another object's vtable pointer when doing a default copy of it
4 // and the vtable pointer involved is the main one.
5 
6 // Correct answer is B::print.
7 // g++ prints D::print, which is wrong.  Cfront gets is right.
8 
9 // prms-id: 2846
10 
11 extern "C" int printf(const char *, ...);
12 extern "C" void exit(int);
13 
14 class B {
15 public:
print(void)16   virtual void print(void) const { printf("B::print\n"); }
17 };
18 
19 class D : public B {
20 public:
print(void)21   void print(void) const { printf("D::print\n"); exit(1); }
22   B compute(void) const;
23 };
24 
compute(void)25 B D::compute(void) const
26 {
27   B sub(*(B*)this);
28   return sub;
29 }
30 
main()31 int main () {
32   D titi;
33   titi.compute().print();
34   return 0;
35 }
36