1// { dg-do run }
2
3extern "C" void abort ();
4
5struct S
6{
7  int s;
8  void foo (S &x) { s += x.s; }
9  S (const S &x) { s = x.s + 1; }
10  S () { s = 6; }
11  ~S () {}
12};
13
14void
15bar (S &x, S &y)
16{
17  if (x.s != 6 || y.s != 6)
18    abort ();
19  x.s = 8;
20}
21
22#pragma omp declare reduction (foo: S: omp_out.foo (omp_in)) \
23	initializer (omp_priv (omp_orig))
24#pragma omp declare reduction (bar : S: omp_out.foo (omp_in)) \
25	initializer (bar (omp_priv, omp_orig))
26
27S
28baz (S x)
29{
30  S r;
31  int i = 0;
32  if (x.s != 7 || r.s != 6)
33    abort ();
34  #pragma omp parallel reduction (foo: x) reduction (bar: r) \
35		       reduction (+: i)
36  {
37    if (x.s != 8 || r.s != 8)
38      abort ();
39    x.s = 12;
40    r.s = 14;
41    i = 1;
42  }
43  if (x.s != 7 + 12 * i || r.s != 6 + 14 * i)
44    abort ();
45  return r;
46}
47
48void
49baz (S &x, S &y)
50{
51  int i = 0, &j = i;
52  #pragma omp parallel reduction (foo: x) reduction (bar: y) \
53		       reduction (+: i)
54  {
55    if (x.s != 7 || y.s != 8)
56      abort ();
57    x.s = 12;
58    y.s = 14;
59    i = 1;
60  }
61  if (x.s != 6 + 12 * j || y.s != 6 + 14 * j)
62    abort ();
63}
64
65int
66main ()
67{
68  S s;
69  baz (s);
70  S t, u;
71  baz (t, u);
72}
73