@@ -8001,6 +8001,51 @@ cxx_eval_constant_expression (const cons
r = cxx_eval_bit_cast (ctx, t, non_constant_p, overflow_p);
break;
+ case OMP_PARALLEL:
+ case OMP_TASK:
+ case OMP_FOR:
+ case OMP_SIMD:
+ case OMP_DISTRIBUTE:
+ case OMP_TASKLOOP:
+ case OMP_LOOP:
+ case OMP_TEAMS:
+ case OMP_TARGET_DATA:
+ case OMP_TARGET:
+ case OMP_SECTIONS:
+ case OMP_ORDERED:
+ case OMP_CRITICAL:
+ case OMP_SINGLE:
+ case OMP_SCAN:
+ case OMP_SCOPE:
+ case OMP_SECTION:
+ case OMP_MASTER:
+ case OMP_MASKED:
+ case OMP_TASKGROUP:
+ case OMP_TARGET_UPDATE:
+ case OMP_TARGET_ENTER_DATA:
+ case OMP_TARGET_EXIT_DATA:
+ case OMP_ATOMIC:
+ case OMP_ATOMIC_READ:
+ case OMP_ATOMIC_CAPTURE_OLD:
+ case OMP_ATOMIC_CAPTURE_NEW:
+ case OMP_DEPOBJ:
+ case OACC_PARALLEL:
+ case OACC_KERNELS:
+ case OACC_SERIAL:
+ case OACC_DATA:
+ case OACC_HOST_DATA:
+ case OACC_LOOP:
+ case OACC_CACHE:
+ case OACC_DECLARE:
+ case OACC_ENTER_DATA:
+ case OACC_EXIT_DATA:
+ case OACC_UPDATE:
+ if (!ctx->quiet)
+ error_at (EXPR_LOCATION (t),
+ "statement is not a constant expression");
+ *non_constant_p = true;
+ break;
+
default:
if (STATEMENT_CODE_P (TREE_CODE (t)))
{
@@ -9471,6 +9516,8 @@ potential_constant_expression_1 (tree t,
case OMP_ORDERED:
case OMP_CRITICAL:
case OMP_SINGLE:
+ case OMP_SCAN:
+ case OMP_SCOPE:
case OMP_SECTION:
case OMP_MASTER:
case OMP_MASKED:
@@ -0,0 +1,47 @@
+// PR c++/108607
+// { dg-do compile { target c++14 } }
+// { dg-options "-fopenmp" }
+
+constexpr int
+bar (int x)
+{
+ return x;
+}
+
+constexpr int
+foo (int x) // { dg-message "declared here" "" { target c++20_down } }
+{ // { dg-message "is not usable as a 'constexpr' function because" "" { target c++23 } .-1 }
+ #pragma omp scope // { dg-warning "is not a constant expression" "" { target c++20_down } }
+ x = bar (x); // { dg-error "is not a constant expression" "" { target c++23 } .-1 }
+ return x;
+}
+
+constexpr int
+baz (int x)
+{
+ switch (x)
+ {
+ case 42:
+ return 0;
+ case 2:
+ #pragma omp scope // { dg-error "statement is not a constant expression" }
+ x = bar (x);
+ return x;
+ case 3:
+ #pragma omp parallel // { dg-error "statement is not a constant expression" }
+ x = bar (x);
+ return x;
+ case 4:
+ #pragma omp task // { dg-error "statement is not a constant expression" }
+ x = bar (x);
+ return x;
+ default:
+ return -1;
+ }
+}
+
+constexpr int a = foo (1); // { dg-error "called in a constant expression" }
+constexpr int b = baz (42);
+constexpr int c = baz (2);
+constexpr int d = baz (3);
+constexpr int e = baz (4);