https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118322
Bug ID: 118322 Summary: [OpenMP] OpenMP in constexpr not properly diagnosed Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: accepts-invalid, diagnostic, openmp Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org Target Milestone: --- OpenMP (up to 6.0) has a rather broad restriction: [C++] Directives may not appear in constexpr functions or in constant expressions Side notes: * While C has constexpr, so far [C23] it has no constexpr functions * There are plans to relax the this restriction, cf. OpenMP spec issue #4454 While there is: cp_parser_omp_construct (cp_parser *parser, cp_token *pragma_tok, bool *if_p) { ... error_at (cp_lexer_peek_token (parser->lexer)->location, "OpenMP directives may not appear in %<constexpr%> functions"); ... } This check is missing from: cp_parser_pragma (cp_parser *parser, enum pragma_context context, bool *if_p) for all directives that directly go to parsing without calling cp_parser_omp_construct. That's the case for: case PRAGMA_OMP_DEPOBJ: case PRAGMA_OMP_FLUSH: case PRAGMA_OMP_INTEROP: case PRAGMA_OMP_TASKWAIT: case PRAGMA_OMP_TASKYIELD: case PRAGMA_OMP_CANCEL: case PRAGMA_OMP_CANCELLATION_POINT: case PRAGMA_OMP_THREADPRIVATE: case PRAGMA_OMP_DECLARE: case PRAGMA_OMP_ALLOCATE: case PRAGMA_OMP_NOTHING: case PRAGMA_OMP_ERROR: case PRAGMA_OMP_ORDERED: case PRAGMA_OMP_TARGET: Disclaimer: I have not checked whether any of those has internally a check nor whether they can be simply moved or whether some special handling needs to be done. Additionally, at least one item will be fixed by a nearly ready patch.