2015-11-30 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / udr-6.C
blob4be821ed0db05068daf116294a7ba58e3fdfd054
1 // { dg-do run }
3 extern "C" void abort ();
5 struct A { int a; A () : a (6) {} };
6 struct B { int b; B () : b (5) {} };
7 struct C { int c; C () : c (4) {} };
8 struct D { int d; D () : d (3) {} };
9 struct E : A, B {};
10 struct F : C, D {};
11 struct G : E, F {};
12 void foo (B &);
13 void foo (F &);
14 #pragma omp declare reduction (+:B:omp_out.b += omp_in.b) \
15                     initializer(foo (omp_priv))
17 void
18 foo (B &x)
20   if (x.b != 5)
21     abort ();
22   x.b = 9;
25 template <typename T>
26 void bar (T &x, T &y, int z)
28   if (z)
29     abort ();
30   x.a += y.a;
33 namespace N1
35   struct A { int a; A () : a (0) {} };
36   #pragma omp declare reduction (+:A:bar (omp_out, omp_in, 0))
38 namespace N2
40   struct B : N1::A { };
41   #pragma omp declare reduction (+:N1::A:bar (omp_out, omp_in, 1))
44 int
45 main ()
47   G g;
48   int i = 0;
49   #pragma omp parallel reduction(+:g, i)
50     {
51       if (g.a != 6 || g.b != 9 || g.c != 4 || g.d != 3)
52         abort ();
53       g.a = 1, g.b = 2, g.c = 3, g.d = 4, i = 1;
54     }
55   if (g.a != 6 || g.b != 5 + 2 * i || g.c != 4 || g.d != 3)
56     abort ();
57   N2::B b;
58   i = 0;
59   #pragma omp parallel reduction (+:b, i)
60     {
61       if (b.a != 0)
62         abort ();
63       b.a = 4;
64       i = 1;
65     }
66   if (b.a != 4 * i)
67     abort ();