Debian Codegraph @

libgomp/testsuite/libgomp.c++/pr26943.C

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