2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / pr61289-2.C
blob4cc3ebe468d4e0279e2c0874735a05e6e3e7019e
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fno-exceptions" } */
3 struct S
5   inline int fn1 () const { return s; }
6   __attribute__ ((noinline, noclone)) S *fn2 (int);
7   __attribute__ ((noinline, noclone)) void fn3 ();
8   __attribute__ ((noinline, noclone)) static S *fn4 (int);
9   S (int i) : s (i) {}
10   int s;
13 int a = 0;
14 S *b = 0;
16 S *
17 S::fn2 (int i)
19   a++;
20   if (a == 1)
21     return b;
22   if (a > 3)
23     __builtin_abort ();
24   b = this;
25   return new S (i + s);
28 S *
29 S::fn4 (int i)
31   b = new S (i);
32   return b;
35 void
36 S::fn3 ()
38   delete this;
41 void
42 foo ()
44   S *c = S::fn4 (20);
45   for (int i = 0; i < 2;)
46     {
47       S *d = c->fn2 (c->fn1 () + 10);
48       if (c != d)
50   c->fn3 ();
51   c = d;
52   ++i;
54     }
55   c->fn3 ();
58 int
59 main ()
61   foo ();