summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/preinc1.C
blob: 89a0116b03547b23d7014d333638c90cc5f0b71b (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// PR optimization/6086
// { dg-do run }
// { dg-options "-O" }
 
extern "C" void abort (void);

struct A
{
  A (int x, int y);
  int a, b;
  int foo () { return a; }
  int bar () { return b; }
};

struct B
{
  virtual ~B ();
  virtual A baz () const;
};

struct C
{
  A foo () const;
  B *c;
};

A C::foo () const
{
  int x, y;
  x = c->baz ().foo ();
  y = c->baz ().bar ();
  return A (x, y);
}

A B::baz () const
{
  return A (4, 8);
}

A::A (int x, int y)
{
  a = x;
  b = y;
}

B::~B ()
{
}

int
main ()
{
  C the_c;
  B the_b;
  the_c.c = &the_b;
  if (the_c.foo().a != 4)
    abort ();
  return 0;
}