[libcxx-commits] [libcxx] [libcxx] implement LWG4148: unique_ptr::operator* should not allow dangling references (PR #128213)
Mohamed Atef via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Nov 8 07:07:52 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
----------------
elhewaty wrote:
@Zingam, I think it requires version >= 23 https://github.com/llvm/llvm-project/blob/main/libcxx/include/__type_traits/reference_converts_from_temporary.h#L28
https://github.com/llvm/llvm-project/pull/128213
More information about the libcxx-commits
mailing list