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

Created on 2026-05-15.00:00:00 last changed yesterday

Messages

Date: 2026-05-16.14:04:41

Proposed resolution:

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`.

Date: 2026-05-15.00:00:00

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

union U { int x = 10; float f; };
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.

History
Date User Action Args
2026-05-16 13:28:22adminsetmessages: + msg16297
2026-05-15 00:00:00admincreate