[libcxx-commits] [libcxx] [libcxx] implement LWG4148: unique_ptr::operator* should not allow dangling references (PR #128213)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 6 20:48:42 PDT 2026


================
@@ -260,6 +261,9 @@ class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI unique_ptr {
 
   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const
       _NOEXCEPT_(_NOEXCEPT_(*std::declval<pointer>())) {
+    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");
----------------
frederick-vs-ja wrote:

I don't think we should mention the _Ugly type template parameter name. Also, it seems unhelpful to note conversion or construction.
```suggestion
        "the returned reference must not bind to a temporary object");
```

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


More information about the libcxx-commits mailing list