2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.dg / opt / nrv5.C
blob7c3c0591f73269a75c2c035b5f4ae45b087d8cc1
1 // PR c++/7279
2 // Test for the named return value optimization with inlining.
3 // Contributed by Jakub Jelinek <jakub@redhat.com>.
4 // { dg-do run }
5 // { dg-options -O2 }
7 enum E { E0, E1, E2, E3 };
9 struct S
11   E s0 : 2;
12   bool s1 : 1, s2 : 1, s3 : 1, s4 : 1, s5 : 1, s6 : 1;
13   S ();
14   void foo (E x);
17 S::S() : s1 (true), s2 (false), s0 (E1), s3 (true), s4 (false),
18          s5 (true), s6 (false) {}
19 void S::foo (E x) { this->s0 = x; }
21 inline S foo ()
23   S s;
24   s.foo (E0);
25   return s;
28 inline S bar ()
30   S s;
31   s.foo (E2);
32   return s;
35 void check (S &s, bool isfoo);
37 void test (bool isfoo)
39   S a = isfoo ? foo () : bar ();
40   check (a, isfoo);
43 extern "C" void abort ();
45 void check (S &s, bool isfoo)
47   if (! s.s1 || s.s2 || ! s.s3 || s.s4 || ! s.s5 || s.s6)
48     abort ();
49   if (s.s0 != (isfoo ? E0 : E2))
50     abort ();
53 int main ()
55   test (true);
56   test (false);