char p_name[sizeof "#pragma omp teams distribute parallel for simd"];
omp_clause_mask mask (0);
- switch (cp_parser_pragma_kind (pragma_tok))
+ unsigned int id = cp_parser_pragma_kind (pragma_tok);
+ if (current_function_decl
+ && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
+ && id >= PRAGMA_OMP__START_
+ && id <= PRAGMA_OMP__LAST_)
+ {
+ error_at (cp_lexer_peek_token (parser->lexer)->location,
+ "OpenMP directives may not appear in %<constexpr%> functions");
+ cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+ return;
+ }
+ switch (id)
{
case PRAGMA_OACC_ATOMIC:
cp_parser_omp_atomic (parser, pragma_tok, true);
cp_parser_skip_to_pragma_eol (parser, pragma_tok);
return false;
}
+ if (current_function_decl
+ && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
+ && id >= PRAGMA_OMP__START_
+ && id <= PRAGMA_OMP__LAST_)
+ {
+ error_at (cp_lexer_peek_token (parser->lexer)->location,
+ "OpenMP directives may not appear in %<constexpr%> functions");
+ cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+ return false;
+ }
+
if (id != PRAGMA_OMP_DECLARE && id != PRAGMA_OACC_ROUTINE)
cp_ensure_no_omp_declare_simd (parser);
switch (id)
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+constexpr int
+f ()
+{
+ int a = 42;
+ #pragma omp parallel for simd /* { dg-error "OpenMP directives may not appear in 'constexpr' functions" } */
+ for (int i=0; i < 10; i++)
+ a += i;
+ return a;
+} // { dg-error "not a return-statement" "" { target c++11_down } }
+
+constexpr int
+g ()
+{
+ int a = 42;
+ [[omp::sequence(omp::directive(parallel),omp::directive(for))]] /* { dg-error "OpenMP directives may not appear in 'constexpr' functions" } */
+ for (int i=0; i < 10; i++)
+ a += i;
+ return a;
+} // { dg-error "not a return-statement" "" { target c++11_down } }
+
+constexpr int
+h ()
+{
+ int a = 42;
+ #pragma omp allocate(a) align(128) /* { dg-error "OpenMP directives may not appear in 'constexpr' functions" } */
+ return a;
+} // { dg-error "not a return-statement" "" { target c++11_down } }
+
+constexpr int
+i ()
+{
+ int a [[omp::decl(allocate, align(128))]] = 42; /* { dg-error "OpenMP directives may not appear in 'constexpr' functions" } */
+ return a;
+} // { dg-error "not a return-statement" "" { target c++11_down } }
+
+
+
+int main() {
+ static constexpr int a = f (); // { dg-error "called in a constant expression" "" { target c++11_down } }
+ static constexpr int b = g (); // { dg-error "called in a constant expression" "" { target c++11_down } }
+ static constexpr int c = h (); // { dg-error "called in a constant expression" "" { target c++11_down } }
+ static constexpr int d = i (); // { dg-error "called in a constant expression" "" { target c++11_down } }
+}
}
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 }
+foo (int x)
+{
+ #pragma omp scope // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
+ x = bar (x);
return x;
}
case 42:
return 0;
case 2:
- #pragma omp scope // { dg-error "statement is not a constant expression" }
+ #pragma omp scope // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
x = bar (x);
return x;
case 3:
- #pragma omp parallel // { dg-error "statement is not a constant expression" }
+ #pragma omp parallel // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
x = bar (x);
return x;
case 4:
- #pragma omp task // { dg-error "statement is not a constant expression" }
+ #pragma omp task // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
x = bar (x);
return x;
default:
}
}
-constexpr int a = foo (1); // { dg-error "called in a constant expression" }
+constexpr int a = foo (1);
constexpr int b = baz (42);
constexpr int c = baz (2);
constexpr int d = baz (3);
f1 ()
{
int i = 0;
-#pragma omp parallel for // { dg-error "is not a constant expression" }
+#pragma omp parallel for // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
for (i = 0; i < 10; ++i)
;
return 0;
f2 ()
{
int i = 0;
-#pragma omp parallel // { dg-error "is not a constant expression" }
+#pragma omp parallel // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 5;
return 0;
}
f3 ()
{
int i = 0;
-#pragma omp task // { dg-error "is not a constant expression" }
+#pragma omp task // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 5;
return 0;
}
f4 ()
{
int i = 0;
-#pragma omp for // { dg-error "is not a constant expression" }
+#pragma omp for // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
for (i = 0; i < 10; ++i)
;
return 0;
f5 ()
{
int i = 0;
-#pragma omp taskloop // { dg-error "is not a constant expression" }
+#pragma omp taskloop // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
for (i = 0; i < 10; ++i)
;
return 0;
f6 ()
{
int i = 0;
-#pragma omp target teams // { dg-error "is not a constant expression" }
+#pragma omp target teams // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 5;
return 0;
}
f7 ()
{
int i = 0;
-#pragma omp target data map(tofrom:i) // { dg-error "is not a constant expression" }
+#pragma omp target data map(tofrom:i) // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 5;
return 0;
}
f8 ()
{
int i = 0;
-#pragma omp target // { dg-error "is not a constant expression" }
+#pragma omp target // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 5;
return 0;
}
f9 ()
{
int i = 0;
-#pragma omp sections // { dg-error "is not a constant expression" }
+#pragma omp sections // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
{
-#pragma omp section
+#pragma omp section // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 5;
}
return 0;
f10 ()
{
int i = 0;
-#pragma omp ordered // { dg-error "is not a constant expression" }
+#pragma omp ordered // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 1;
return 0;
}
f11 ()
{
int i = 0;
-#pragma omp critical // { dg-error "is not a constant expression" }
+#pragma omp critical // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 1;
return 0;
}
f12 ()
{
int i = 0;
-#pragma omp single // { dg-error "is not a constant expression" }
+#pragma omp single // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 1;
return 0;
}
f13 ()
{
int i = 0;
-#pragma omp master // { dg-error "is not a constant expression" }
+#pragma omp master // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 1;
return 0;
}
f14 ()
{
int i = 0;
-#pragma omp taskgroup // { dg-error "is not a constant expression" }
+#pragma omp taskgroup // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 1;
return 0;
}
f15 ()
{
int i = 0;
-#pragma omp target update to(i) // { dg-error "is not a constant expression" }
+#pragma omp target update to(i) // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
i = 1;
return 0;
}
f16 ()
{
int i = 0;
-#pragma omp target update to(i) // { dg-error "is not a constant expression" }
+#pragma omp target update to(i) // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
return 0;
}
f17 ()
{
int i = 0;
-#pragma omp target enter data map(to:i) // { dg-error "is not a constant expression" }
+#pragma omp target enter data map(to:i) // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
return 0;
}
f18 ()
{
int i = 0;
-#pragma omp target exit data map(from:i) // { dg-error "is not a constant expression" }
+#pragma omp target exit data map(from:i) // { dg-error "OpenMP directives may not appear in 'constexpr' functions" }
return 0;
}