This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
is_within_lifetime should mandate is_objectSection: 21.3.11 [meta.const.eval] Status: New Submitter: Corentin Opened: 2024-08-09 Last modified: 2026-06-10
Priority: 3
View all issues with New status.
Discussion:
int f(); std::is_within_lifetime<int()>(f);
This is currently well-formed, and only fails when evaluated because
is_within_lifetime is not constrained. However talking of lifetime
of a non-object does not make sense, and the lack of constraint makes the
implementation and use of that function and underlying built-in more
convoluted than necessary.
[2025-10-14; Reflector poll]
Set priority to 3 after reflector poll.
"What about void*, should that be allowed? The compiler should know which
union member the void* came from, as this is only using during constant
evaluation."
"NAD, a function could have its lifetime constrained by a dynamic loader, so it seems wrong to assume that taling of function lifetimes makes no sense."
This wording is relative to N4988.
Modify 21.3.3 [meta.type.synop], header <type_traits> synopsis, as indicated:
[…] // 21.3.11 [meta.const.eval], constant evaluation context constexpr bool is_constant_evaluated() noexcept; template<class T> consteval bool is_within_lifetime(const Tauto*) noexcept;
Modify 21.3.11 [meta.const.eval] as indicated:
template<class T> consteval bool is_within_lifetime(const Tauto* p) noexcept;-?- Mandates:
-3- Returns:is_object_v<T>istrue.trueifpis a pointer to an object that is within its lifetime (6.8.4 [basic.life]); otherwise,false. -4- Remarks: During the evaluation of an expressionEas a core constant expression, a call to this function is ill-formed unlessppoints to an object that is usable in constant expressions or whose complete object's lifetime began withinE.
[2026-06-09; Tim rebases and provides new wording]
Functions do not have lifetimes as far as the standard is concerned. However, there is no reason to ban void.
Proposed resolution:
This wording is relative to N5046.
Modify 21.3.11 [meta.const.eval] as indicated:
template<class U = void, class T> consteval bool is_within_lifetime(const T* p) noexcept;-3- Mandates:
-4- Returns:static_cast<const volatile U*>(p)is well-formed.Tis an object type or cvvoid.trueifpis a pointer to an object that is within its lifetime (6.8.4 [basic.life]) andstatic_cast<const volatile U*>(p)is a constant subexpression; otherwise,false. -4- Remarks: During the evaluation of an expressionEas a core constant expression, a call to this function is ill-formed unlessppoints to an object that is usable in constant expressions or whose complete object's lifetime began withinE.