Merged with mainline at revision 128810.
[official-gcc.git] / gcc / testsuite / g++.dg / gomp / sharing-1.C
blob25626ff2028949bfa5f577981db65108a335afa9
1 /* { dg-do compile } */
2 /* { dg-require-effective-target tls_native } */
4 int thrglobalvar;
5 #pragma omp threadprivate (thrglobalvar)
6 int globalvar;
7 const struct S
9   int x;
10 } constvar = { 8 };
11 struct T
13   static T t;
14   int i;
16 T T::t = { 6 };
17 /* const qualified type, but mutable member -> not predetermined.  */
18 const struct U
20   int x;
21   mutable int y;
22 } constmutvar = { 6, 4 };
24 int
25 foo (int x)
27   return x;
30 int
31 bar (int *x)
33   return *x;
36 int
37 baz (U u)
39   return u.x;
42 int
43 main (void)
45   static int thrlocvar;
46 #pragma omp threadprivate (thrlocvar)
47   static int locvar;
48   static int *p;
49   int i, j, s, l;
51   p = new int;
52   *p = 7;
53   s = 6;
54   l = 0;
55 #pragma omp parallel for /* { dg-error "enclosing parallel" } */ \
56   default (none) private (p) shared (s) 
57   for (i = 0; i < 64; i++)
58     {
59       int k = foo (0);  /* Predetermined - private (automatic var declared */
60       k++;              /* in scope of construct).  */
61       thrglobalvar++;   /* Predetermined - threadprivate.  */
62       thrlocvar++;      /* Predetermined - threadprivate.  */
63       foo (i);          /* Predetermined - private (omp for loop variable).  */
64       foo (constvar.x); /* Predetermined - shared (const qualified type).  */
65       foo (T::t.i);     /* Predetermined - shared (static data member).  */
66       foo (*p);         /* *p predetermined - shared (heap allocated */
67       (*p)++;           /* storage).  */
68       bar (p);          /* Explicitly determined - private.  */
69       foo (s);          /* Explicitly determined - shared.  */
70       globalvar++;      /* { dg-error "not specified in" } */
71       locvar++;         /* { dg-error "not specified in" } */
72       l++;              /* { dg-error "not specified in" } */
73       for (j = 0; j < 2; j++); /* { dg-error "not specified in" } */
74       baz (constmutvar);/* { dg-error "not specified in" } */
75     }
76   return 0;