2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / udr-5.C
blob91ae2f697c3d48030a0ceeec9c323ba67f2def56
1 // { dg-do run }
3 extern "C" void abort ();
5 struct S
7   void foo ()
8   {
9     S s;
10     int j = 0;
11     #pragma omp declare reduction (bar : int : omp_out += omp_in)
12     #pragma omp parallel reduction (bar : s) reduction(S::operator+ : j)
13     s.a = 4, j = 1;
14     if (s.a != 4 * j) abort ();
15   }
16   #pragma omp declare reduction (bar : S : baz (omp_out, omp_in))
17   static void baz (S &x, S &y) { x.a += y.a; }
18   S () : a (0) {}
19   int a;
22 template <int N>
23 struct T
25   void foo ()
26   {
27     S s;
28     T t;
29     int j = 0;
30     #pragma omp declare reduction (bar : int : omp_out += omp_in)
31     #pragma omp parallel reduction (bar : t) reduction (S::bar : s) \
32                          reduction(T<N>::operator+ : j)
33     s.a = 4, t.a = 5, j = 1;
34     if (s.a != 4 * j || t.a != 5 * j) abort ();
35   }
36   #pragma omp declare reduction (bar : T<N> : baz (omp_out, omp_in))
37   static void baz (T &x, T &y) { x.a += y.a; }
38   T () : a (N) {}
39   int a;
42 int
43 main ()
45   S s;
46   s.foo ();
47   T<0> t;
48   t.foo ();