[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 Dec 6 10:04:33 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:
> We should introduce a private version of the trait instead, i.e. `__reference_constructs_from_temporary_v`. I think that is what @Zingam meant.
@philnik777, @Zingam can you please help me understanding this? should I revert this https://github.com/llvm/llvm-project/commit/a1e77d20883d90186f7ea1cd184b09d0878c667d#diff-cfa44dc4db9caf101a253c6f6db926764176ac7ff62744a7776949b83c1ad26dL24? do you have an example of private and public trait or function?
https://github.com/llvm/llvm-project/pull/128213
More information about the libcxx-commits
mailing list