Title
§[meta.reflection.extract] has a circular requirement when extracting a variable during its own initialization
Status
new
Section
[meta.reflection.extract]
Submitter
Murat Can Çağrı

Created on 2026-08-17.00:00:00 last changed 1 week ago

Messages

Date: 2026-08-17.00:00:00

Consider:

constexpr int const& r = std::meta::extract<int const&>(^^r);

For the call to extract-ref, [meta.reflection.extract]/5.3 requires that, if the reflection represents a variable, either:

  • the variable is usable in constant expressions, or

  • its lifetime began within the core constant expression currently under evaluation.

The second does not apply, as [basic.life] says the lifetime of the reference begins after its initialization is complete.

The first, is circular. Determining whether `r` is usable in constant expression requires determining whether it is constant-initialized, which requires whether the full-expression of the initializer is a constant expression. Determining whether that full-expression is constant expression requires evaluating the call to extract, whose successful evaluation depends on the same determination that `r` is usable in constant expressions.

Also, [meta.reflection.extract]/4 says the result is a reference to object referred by the represented variable, which during the initialization of `r`, doesn't exist yet.

Apparent intent is presumably to make this ill-formed, but the current wording does not provide a non-circular way of reaching that conclusion.

Suggested resolution:

Require that the lifetime of the object or reference declared by the represented variable has already begun.

History
Date User Action Args
2026-08-17 00:00:00admincreate