1// PR c++/36308
2// { dg-do run }
3
4#include <omp.h>
5#include <assert.h>
6
7#define N 10
8
9struct B
10{
11  static int icount;
12  static int ccount;
13  static int dcount;
14  static int xcount;
15
16  B ();
17  B (const B &);
18  virtual ~B ();
19  B& operator= (const B &);
20  void doit ();
21  static void clear () { icount = ccount = dcount = xcount = 0; }
22};
23
24int B::icount;
25int B::ccount;
26int B::dcount;
27int B::xcount;
28
29B::B ()
30{
31  #pragma omp atomic
32    icount++;
33}
34
35B::B (const B &)
36{
37  #pragma omp atomic
38    ccount++;
39}
40
41B::~B ()
42{
43  #pragma omp atomic
44    dcount++;
45}
46
47void
48B::doit ()
49{
50  #pragma omp atomic
51    xcount++;
52}
53
54static int nthreads;
55
56void
57test1 ()
58{
59  B b[N];
60  #pragma omp parallel private (b)
61    {
62      #pragma omp master
63	nthreads = omp_get_num_threads ();
64      b[0].doit ();
65    }
66}
67
68void
69test2 ()
70{
71  B b;
72  #pragma omp parallel firstprivate (b)
73    {
74      #pragma omp single
75	nthreads = omp_get_num_threads ();
76      b.doit ();
77    }
78}
79
80int
81main ()
82{
83  omp_set_dynamic (0);
84  omp_set_num_threads (4);
85
86  B::clear ();
87  test1 ();
88  assert (B::xcount == nthreads);
89  assert (B::ccount == 0);
90  assert (B::icount == (nthreads + 1) * N);
91  assert (B::dcount == (nthreads + 1) * N);
92
93  B::clear ();
94  test2 ();
95  assert (B::xcount == nthreads);
96  assert (B::ccount == nthreads);
97  assert (B::icount == 1);
98  assert (B::dcount == nthreads + 1);
99  return 0;
100}
101