[libcxx-commits] [libcxx] [libc++] Implement P3450R1: Extend `std::is_within_lifetime` (PR #201053)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 16 01:33:48 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:

> In that case, i don't understand why don't we directly modify `__builtin_is_within_lifetime` , which should be a simpler change than this PR , which needs to use `__builtin_constant_p` in a weird way

Hmm, I don't know how can direct modification of `__builtin_is_within_lifetime` be simpler, given the current workaround only needs to change 2~3 lines in the product code. Modification of `__builtin_is_within_lifetime` certainly requires changing far more lines in the Clang frontend and needs test coverage for Clang together.

https://github.com/llvm/llvm-project/pull/201053


More information about the libcxx-commits mailing list