[libcxx-commits] [libcxx] [libc++] P3450R1: Extend `std::is_within_lifetime` (PR #201053)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jun 12 04:59:40 PDT 2026
================
@@ -18,9 +18,9 @@
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 26 && __has_builtin(__builtin_is_within_lifetime)
-template <class _Tp>
+template <class _Up = void, class _Tp>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI consteval bool is_within_lifetime(const _Tp* __p) noexcept {
- return __builtin_is_within_lifetime(__p);
+ return __builtin_is_within_lifetime(__p) && __builtin_constant_p(static_cast<const volatile _Up*>(__p) && true);
----------------
frederick-vs-ja wrote:
`__builtin_constant_p` will always gives `false` if we use `__builtin_constant_p(static_cast<const volatile _Up*>(__p))` as-is. I think this is because of that `__builtin_constant_p` checks whether the final result is a constant expression, not merely where the operand is constant-evaluable.
`&& false`, `|| true`, `|| false`, `? 0 : 0`, and `((void)(expr), 0)` equivalently work.
https://github.com/llvm/llvm-project/pull/201053
More information about the libcxx-commits
mailing list