summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/nrv5.C
blob: 7c3c0591f73269a75c2c035b5f4ae45b087d8cc1 (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
// PR c++/7279
// Test for the named return value optimization with inlining.
// Contributed by Jakub Jelinek <jakub@redhat.com>.
// { dg-do run }
// { dg-options -O2 }

enum E { E0, E1, E2, E3 };

struct S
{
  E s0 : 2;
  bool s1 : 1, s2 : 1, s3 : 1, s4 : 1, s5 : 1, s6 : 1;
  S ();
  void foo (E x);
};

S::S() : s1 (true), s2 (false), s0 (E1), s3 (true), s4 (false),
	 s5 (true), s6 (false) {}
void S::foo (E x) { this->s0 = x; }

inline S foo ()
{
  S s;
  s.foo (E0);
  return s;
}

inline S bar ()
{
  S s;
  s.foo (E2);
  return s;
}

void check (S &s, bool isfoo);

void test (bool isfoo)
{
  S a = isfoo ? foo () : bar ();
  check (a, isfoo);
}

extern "C" void abort ();

void check (S &s, bool isfoo)
{
  if (! s.s1 || s.s2 || ! s.s3 || s.s4 || ! s.s5 || s.s6)
    abort ();
  if (s.s0 != (isfoo ? E0 : E2))
    abort ();
}

int main ()
{
  test (true);
  test (false);
}