[libcxx-commits] [libcxx] [libcxx] LWG4172 fix self-move-assignment in {unique|shared}_lock (PR #129542)

Mohamed Atef via libcxx-commits libcxx-commits at lists.llvm.org
Sat Dec 6 10:03:38 PST 2025


================
@@ -74,13 +77,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);
----------------
elhewaty wrote:

@ldionne it still fails, I also guarded the initialization to check for self move first as I thought there maybe
a something unexpected in swap implementation.
but one thing comes across my mind, std::move is C++11 feature so in frozen-C++03 test it fallback to the copy constructor which may fire the assertion in the failure. If so can we disable the test for C++03,
unique/shared_lock are not in C++03 anyway?

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


More information about the libcxx-commits mailing list