-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libcxx] LWG4172 fix self-move-assignment in {unique|shared}_lock #129542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should include _LIBCPP_PUSH_MACROS
#include <__undef_macros>immediately before _LIBCPP_BEGIN_NAMESPACE_STD, and _LIBCPP_POP_MACROSimmediately after _LIBCPP_END_NAMESPACE_STD |
||
| return *this; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,22 +21,31 @@ | |
|
|
||
| #include "test_macros.h" | ||
|
|
||
|
|
||
| int main(int, char**) | ||
| { | ||
| { | ||
| int main(int, char**) { | ||
| { | ||
| typedef std::shared_timed_mutex M; | ||
| M m0; | ||
| M m1; | ||
| std::shared_lock<M> lk0(m0); | ||
| std::shared_lock<M> lk1(m1); | ||
|
|
||
| // Test self move assignment for lk0. | ||
| lk0 = std::move(lk0); | ||
| assert(lk0.mutex() == std::addressof(m0)); | ||
| assert(lk0.owns_lock() == true); | ||
|
|
||
| lk1 = std::move(lk0); | ||
| assert(lk1.mutex() == std::addressof(m0)); | ||
| assert(lk1.owns_lock() == true); | ||
| assert(lk0.mutex() == nullptr); | ||
| assert(lk0.owns_lock() == false); | ||
| } | ||
| { | ||
|
|
||
| // Test self move assignment for lk1. | ||
| lk1 = std::move(lk1); | ||
| assert(lk1.mutex() == std::addressof(m0)); | ||
| assert(lk1.owns_lock() == true); | ||
| } | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this test does not validate the |
||
| typedef nasty_mutex M; | ||
| M m0; | ||
| M m1; | ||
|
|
@@ -47,7 +56,7 @@ int main(int, char**) | |
| assert(lk1.owns_lock() == true); | ||
| assert(lk0.mutex() == nullptr); | ||
| assert(lk0.owns_lock() == false); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically for this LWG issue you need to update the synopsis due to the adding of
noexcept, but that seems already done.