[libcxx-commits] [libcxx] [libcxx] implement LWG4148: unique_ptr::operator* should not allow dangling references (PR #128213)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 7 23:23:08 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
----------------
Zingam wrote:
```suggestion
static_assert(
!__reference_converts_from_temporary_v(__add_lvalue_reference_t<_Tp>, decltype(*std::declval<pointer>())),
"Reference type _Tp must not convert from a temporary object");
```
Can we already replace all of this with a private function: `__reference_converts_from_temporary_v` as instructed previously? See:
https://github.com/llvm/llvm-project/blob/0875755f5275dc7a84b1aeb526b7822b47a733c9/libcxx/include/__type_traits/reference_constructs_from_temporary.h#L34
https://github.com/llvm/llvm-project/pull/128213
More information about the libcxx-commits
mailing list