9 The
constexpr and consteval specifiers
9.1 The
constexpr and consteval specifiers
[dcl.constexpr]
Except as modified by this clause, [dcl.constexpr] applies unchanged to a SCPP26 program.
The tokens
constexprandconstevalhave the meanings assigned by the C++ standard; this document introduces no additional spelling for compile-time-evaluable declarations.A function or constructor declared
constexpris eligible for compile-time evaluation. If an invocation of such a function or constructor occurs in required constant evaluation (7.1), the invocation shall satisfy Clause 7. Otherwise, the invocation is an ordinary runtime invocation with the semantics the C++ standard gives it.A function or constructor declared
constevalis an immediate function. Every potentially-evaluated call to it shall produce a constant expression. If it does not, the program is ill-formed.A destructor, allocation function, or deallocation function shall not be declared
consteval.A
constexprorconstevalconstructor may participate in required constant evaluation only for a class type satisfying 7.2(2).
[Note: this clause reuses the C++ spellings and meanings of
constexpr and consteval. The SCPP26-specific
restrictions are those of Clause 7βs supported constant-evaluation
subset. β end note]
9.2 The
if consteval statement [stmt.if]
An
ifstatement of the formif constevalis a consteval if statement. Anifstatement of the formif !constevalis a negated consteval if statement.Except as modified by this subclause, [stmt.if] applies unchanged to a consteval if statement or negated consteval if statement.
If a consteval if statement is evaluated in a context that is manifestly constant-evaluated ([expr.const.defns]), the first substatement is executed. That first substatement is an immediate function context.
Otherwise, if the else part of a consteval if statement is present, the second substatement is executed.
If a negated consteval if statement is evaluated in a context that is manifestly constant-evaluated ([expr.const.defns]), the first substatement is not executed and, if the else part is present, the second substatement is executed.
Otherwise, the first substatement of a negated consteval if statement is executed.
Each substatement of a consteval if statement or negated consteval if statement is a control-flow-limited statement ([stmt.label]).
β Previous: Constant evaluation Β· Table of Contents Β· Next: Function template argument deduction β