[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 19 10:56:55 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:
> Wouldn't it be better to use this implementation as a temporary workaround and to update the builtin itself to provide the updated functionality?
I think we can treat use of `__builtin_constant_p` as a workaround, and currently this PR is doing so.
> Are there any other uses for `__builtin_is_within_lifetime` that require just the initial functionality?
No, I think. `__builtin_is_within_lifetime` is quite specific to `std::is_within_lifetime`.
> I'd find it strange that the builtin with the same name as std::is_within_lifetime supports just some of it.
Agree. I just wanted to enable the library change without compiler change. Also, it seems to me that we can change less code in the whole LLVM codebase with the workaround.
https://github.com/llvm/llvm-project/pull/201053
More information about the libcxx-commits
mailing list