Title
`std::start_lifetime(r)` should not be able to poke objects outside the current evaluation
Status
core
Section
[obj.lifetime]
Submitter
Tomasz Kamiński

Created on 2026-05-15.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-05-15.00:00:00

[ 2026-05-22; LWG telecon. Status → Core. ]

Corrected example, to make it well-formed.

The recommendation is to include general prohibition in [expr.const.core], that would prevent us from starting lifetime of object outside current evaluation.

Date: 2026-05-22.16:40:24

As currently specified, the following code is well-formed:

union U { int x = 10; float f[2]; };
U u;

consteval {
  std::start_lifetime(u.f); // changes active member
};

void foo() {
  U u;
  constexpr int x = (std::start_lifetime(u.f), 10);
}

The `start_lifetime(r)` when evaluated at compile time, should require that `r` is a subobject of the object created during the enclosing constant evaluation.

This wording is relative to N5046.

  1. Modify [obj.lifetime] as indicated:

    template<class T>
      constexpr void start_lifetime(T& r) noexcept;
    

    -1- Mandates: `T` is a complete type and an implicit-lifetime ([basic.types]) aggregate ([dcl.init.aggr]).

    -?- Constant When: `r` refers to a non-volatile object whose lifetime began within the evaluation of the core constant expression ([expr.const.core]) which includes the invocation of `start_lifetime`, or a sub-object of such an object.

    -2- Effects: If the object referenced by `r` is already within its lifetime ([basic.life]), no effects. Otherwise, begins the lifetime of the object referenced by `r`.

History
Date User Action Args
2026-05-22 16:40:24adminsetstatus: new -> core
2026-05-16 13:28:22adminsetmessages: + msg16297
2026-05-15 00:00:00admincreate