aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/pr61289-2.c
blob: 4cc3ebe468d4e0279e2c0874735a05e6e3e7019e (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
60
61
62
/* { dg-do run } */
/* { dg-options "-O2 -fno-exceptions" } */
struct S
{
  inline int fn1 () const { return s; }
  __attribute__ ((noinline, noclone)) S *fn2 (int);
  __attribute__ ((noinline, noclone)) void fn3 ();
  __attribute__ ((noinline, noclone)) static S *fn4 (int);
  S (int i) : s (i) {}
  int s;
};

int a = 0;
S *b = 0;

S *
S::fn2 (int i)
{
  a++;
  if (a == 1)
    return b;
  if (a > 3)
    __builtin_abort ();
  b = this;
  return new S (i + s);
}

S *
S::fn4 (int i)
{
  b = new S (i);
  return b;
}

void
S::fn3 ()
{
  delete this;
}

void
foo ()
{
  S *c = S::fn4 (20);
  for (int i = 0; i < 2;)
    {
      S *d = c->fn2 (c->fn1 () + 10);
      if (c != d)
{
  c->fn3 ();
  c = d;
  ++i;
}
    }
  c->fn3 ();
}

int
main ()
{
  foo ();
}