[libcxx-commits] [libcxx] [libcxx] LWG4172 fix self-move-assignment in {unique|shared}_lock (PR #129542)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 24 00:28:18 PDT 2025
================
@@ -74,13 +74,7 @@ class unique_lock {
}
_LIBCPP_HIDE_FROM_ABI unique_lock& operator=(unique_lock&& __u) _NOEXCEPT {
- if (__owns_)
- __m_->unlock();
-
- __m_ = __u.__m_;
- __owns_ = __u.__owns_;
- __u.__m_ = nullptr;
- __u.__owns_ = false;
+ unique_lock{std::move(__u)}.swap(*this);
----------------
frederick-vs-ja wrote:
You should include `<__utility/move.h>` in `<__mutex/unique_lock.h>` and `<shared_mutex>`. And then you need to add
```C++
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
```
immediately before
```C++
_LIBCPP_BEGIN_NAMESPACE_STD
```
, and
```C++
_LIBCPP_POP_MACROS
```
immediately after
```C++
_LIBCPP_END_NAMESPACE_STD
```
https://github.com/llvm/llvm-project/pull/129542
More information about the libcxx-commits
mailing list