[libcxx-commits] [libcxx] [libc++][unique_ptr] Implement LWG 4144: Disallow unique_ptr<T&, D> (PR #209018)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 13 02:36:10 PDT 2026


================
@@ -100,6 +101,12 @@ inline const bool __can_dereference = false;
 template <class _Tp>
 inline const bool __can_dereference<_Tp, decltype((void)*std::declval<_Tp>())> = true;
 
+template <class _Tp, class = void>
+inline const bool __is_pointable = false;
----------------
emmett2020 wrote:

Thanks for the review. `__can_add_pointer` seems more descriptive than `__is_pointable`. I've changed the variable name now.

I don't think we can use `!is_same<__add_pointer_t<_Tp>, _Tp>`. `__add_pointer_t` will remove reference first .

https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaType.cpp#L10168. 

So 
```
For unique_ptr<int&, D>, _Tp is int&:

__add_pointer_t<int&>       -> int*
!is_same<int*, int&>::value -> true
static_assert(...)          -> passes

Therefore, this condition would fail to reject unique_ptr<int&, D>
```


Yes, `requires { _Tp*}` is so clear! Unfortunately, there is a version limitation :)

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


More information about the libcxx-commits mailing list