Title
Constant lvalue-to-rvalue conversion on uninitialized std::nullptr_t
Status
open
Section
7.7 [expr.const]
Submitter
Jim X

Created on 2023-01-10.00:00:00 last changed 20 months ago

Messages

Date: 2024-06-19.04:39:51

(From submission #215.)

Consider:

  void f() {
    std::nullptr_t np;       // uninitialized, thus np contains an erroneous value
    constexpr void *p1 = np; // error: converted initializer is not a constant expression
  }

The lvalue-to-rvalue conversion on np does not actually read the value of np (7.3.2 [conv.lval] bullet 3.1), yet the situation is made ill-formed by 7.7 [expr.const] bullet 5.9.

Possible resolution:

Change in 7.7 [expr.const] bullet 5.9 as follows:

An expression E is a core constant expression unless the evaluation of E, following the rules of the abstract machine (6.9.1 [intro.execution]), would evaluate one of the following:
  • ...
  • an lvalue-to-rvalue conversion (7.3.2 [conv.lval]) unless it is applied to
    • a glvalue of type cv std::nullptr_t,
    • a non-volatile glvalue that refers to an object that is usable in constant expressions, or
    • a non-volatile glvalue of literal type that refers to a non-volatile object whose lifetime began within the evaluation of E;
  • ...
History
Date User Action Args
2023-01-10 00:00:00admincreate