Skip to content

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

@wg21bot

Description

@wg21bot

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions