cplusplus / nbballot

Handling of NB comments in response to ballots
14 stars 4 forks source link

GB-048 7.7 [expr.const] Remove restriction on local static variables in core constant expressions #443

Closed wg21bot closed 1 year ago

wg21bot commented 1 year ago

This is ill-formed:

constexpr char xdigit(int n) {
static constexpr char x[] = "0123456789abcdef";
  return x[n];
}

[expr.const] (5.2) disallows "a control flow that passes through a declaration of a variable with static (6.7.5.2) or thread (6.7.5.3) storage duration;"

But the restriction is unnecessary if the variable can be constant initialized. This causes difficulties when implementing P2291R3, "Add Constexpr Modifiers to Functions to_chars and from_chars for Integral Types in <charconv> Header".

Allow local static variables in constant expressions, if they are constant-initialized.

jensmaurer commented 1 year ago

CWG 2022-11-07: Should be reviewed by EWG.

jensmaurer commented 1 year ago

See P2647 cplusplus/papers#1318

erichkeane commented 1 year ago

Forward P2647R0 to CWG for inclusion in C++23, increasing __cpp_constexpr in the process.

SF F N A SA
3 14 3 2 1

Result: Consensus

jensmaurer commented 1 year ago

CWG 2022-11-08: Accepted with Modifications. See paper P2647R1 for details.