aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.mike/p2846a.C
blob: 363ed5b0177c6e02d4bb9a38633c1bf66db1d3f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Shows that problem of initializing one object's vtable pointer from
// another object's vtable pointer when doing a default copy of it
// and the vtable pointer involved is the main one.

// Correct answer is B::print.
// g++ prints D::print, which is wrong.  Cfront gets is right.

// prms-id: 2846

extern "C" int printf(const char *, ...);
extern "C" void exit(int);

class B {
public:
  virtual void print(void) const { printf("B::print\n"); }
};

class D : public B {
public:
  void print(void) const { printf("D::print\n"); exit(1); }
  B compute(void) const;
};

B D::compute(void) const
{
  B sub(*(B*)this);
  return sub;
}

main () {
  D titi;
  titi.compute().print();
  return 0;
}