@@ -6634,9 +6634,11 @@ omp_add_variable (struct gimplify_omp_ct
return;
/* Never elide decls whose type has TREE_ADDRESSABLE set. This means
- there are constructors involved somewhere. */
- if (TREE_ADDRESSABLE (TREE_TYPE (decl))
- || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
+ there are constructors involved somewhere. Exception is a shared clause,
+ there is nothing privatized in that case. */
+ if ((flags & GOVD_SHARED) == 0
+ && (TREE_ADDRESSABLE (TREE_TYPE (decl))
+ || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
flags |= GOVD_SEEN;
n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
@@ -0,0 +1,41 @@
+// PR c++/81130
+// { dg-do run }
+
+struct A
+{
+ A ();
+ ~A ();
+ int a;
+};
+
+A::A ()
+{
+ a = 0;
+}
+
+A::~A ()
+{
+}
+
+struct B
+{
+ A b;
+ int c;
+ B () : c (1)
+ {
+#pragma omp parallel shared (b, c) num_threads (2)
+#pragma omp master
+ {
+ b.a++;
+ c += 2;
+ }
+ }
+};
+
+int
+main ()
+{
+ B v;
+ if (v.b.a != 1 || v.c != 3)
+ __builtin_abort ();
+}