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