diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d8b20ff5b1b..356fb83200c 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9325,6 +9325,9 @@ finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr) return NULL_TREE; } + if (TREE_CODE (t) == OMP_CLAUSE) + return NULL_TREE; + if (current_object) { tree this_expr = TREE_OPERAND (current_object, 0); diff --git a/gcc/testsuite/g++.dg/gomp/pr103704.C b/gcc/testsuite/g++.dg/gomp/pr103704.C new file mode 100644 index 00000000000..68767c4c055 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/pr103704.C @@ -0,0 +1,19 @@ +// PR c++/103704 +// { dg-do compile } + +struct S { int a; }; + +template +struct U : public T { + T a; + U () + { +#pragma omp target +#pragma omp teams +#pragma omp distribute private(a) + for (int k = 0; k < 1; ++k) + ; + } +}; + +struct V : public U { V () : U () {} };