[libcxx-commits] [libcxx] [libcxx] implement LWG4148: unique_ptr::operator* should not allow dangling references (PR #128213)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 10 03:34:09 PST 2025
================
@@ -265,6 +265,14 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const
_NOEXCEPT_(_NOEXCEPT_(*std::declval<pointer>())) {
+ // TODO(LLVM-21): Remove this workaround
+#if __has_builtin(__reference_converts_from_temporary) || \
+ (defined(_LIBCPP_CLANG_VER) && \
+ ((!defined(__ANDROID__) && _LIBCPP_CLANG_VER >= 1901) || (defined(__ANDROID__) && _LIBCPP_CLANG_VER >= 2000)))
+ static_assert(
+ !__reference_converts_from_temporary(__add_lvalue_reference_t<_Tp>, decltype(*std::declval<pointer>())),
+ "Reference type _Tp must not convert from a temporary object");
+#endif
----------------
philnik777 wrote:
We should introduce a private version of the trait instead, i.e. `__reference_constructs_from_temporary_v`. I think that is what @Zingam meant.
https://github.com/llvm/llvm-project/pull/128213
More information about the libcxx-commits
mailing list