xref: /openbsd-src/gnu/gcc/libgomp/testsuite/libgomp.c++/pr26943.C (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // PR c++/26943
2*404b540aSrobert // { dg-do run }
3*404b540aSrobert 
4*404b540aSrobert #include <assert.h>
5*404b540aSrobert #include <unistd.h>
6*404b540aSrobert 
7*404b540aSrobert struct S
8*404b540aSrobert {
9*404b540aSrobert   public:
10*404b540aSrobert     int x;
SS11*404b540aSrobert     S () : x(-1) { }
12*404b540aSrobert     S (const S &);
13*404b540aSrobert     S& operator= (const S &);
14*404b540aSrobert     void test ();
15*404b540aSrobert };
16*404b540aSrobert 
17*404b540aSrobert static volatile int hold;
18*404b540aSrobert 
S(const S & s)19*404b540aSrobert S::S (const S &s)
20*404b540aSrobert {
21*404b540aSrobert   #pragma omp master
22*404b540aSrobert     sleep (1);
23*404b540aSrobert 
24*404b540aSrobert   assert (s.x == -1);
25*404b540aSrobert   x = 0;
26*404b540aSrobert }
27*404b540aSrobert 
28*404b540aSrobert S&
29*404b540aSrobert S::operator= (const S& s)
30*404b540aSrobert {
31*404b540aSrobert   assert (s.x == 1);
32*404b540aSrobert   x = 2;
33*404b540aSrobert   return *this;
34*404b540aSrobert }
35*404b540aSrobert 
36*404b540aSrobert void
test()37*404b540aSrobert S::test ()
38*404b540aSrobert {
39*404b540aSrobert   assert (x == 0);
40*404b540aSrobert   x = 1;
41*404b540aSrobert }
42*404b540aSrobert 
43*404b540aSrobert static S x;
44*404b540aSrobert 
45*404b540aSrobert void
foo()46*404b540aSrobert foo ()
47*404b540aSrobert {
48*404b540aSrobert   #pragma omp sections firstprivate(x) lastprivate(x)
49*404b540aSrobert   {
50*404b540aSrobert     x.test();
51*404b540aSrobert   }
52*404b540aSrobert }
53*404b540aSrobert 
54*404b540aSrobert int
main()55*404b540aSrobert main ()
56*404b540aSrobert {
57*404b540aSrobert   #pragma omp parallel num_threads(2)
58*404b540aSrobert     foo();
59*404b540aSrobert 
60*404b540aSrobert   assert (x.x == 2);
61*404b540aSrobert   return 0;
62*404b540aSrobert }
63