Skip to content

Commit

Permalink
Fix self-move-assignment for proxy (#59)
Browse files Browse the repository at this point in the history
* Fix self-move-assignment for `proxy`

* Fix test
  • Loading branch information
frederick-vs-ja authored Jan 18, 2024
1 parent 531dfcc commit deee3c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 7 additions & 5 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,14 @@ class proxy {
proxy& operator=(const proxy&) requires(!HasCopyAssignment) = delete;
proxy& operator=(proxy&& rhs) noexcept(HasNothrowMoveAssignment)
requires(HasMoveAssignment) {
if constexpr (HasNothrowMoveAssignment) {
this->~proxy();
} else {
reset(); // For weak exception safety
if (this != &rhs) {
if constexpr (HasNothrowMoveAssignment) {
this->~proxy();
} else {
reset(); // For weak exception safety
}
new(this) proxy(std::move(rhs));
}
new(this) proxy(std::move(rhs));
return *this;
}
proxy& operator=(proxy&&) requires(!HasMoveAssignment) = delete;
Expand Down
6 changes: 2 additions & 4 deletions tests/proxy_lifetime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,10 @@ TEST(ProxyLifetimeTests, TestMoveAssignment_FromValue_ToSelf) {
#elif defined(__GNUC__) && __GNUC__ >= 13
#pragma GCC diagnostic pop
#endif // __clang__
ASSERT_FALSE(p.has_value());
expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction);
expected_ops.emplace_back(2, utils::LifetimeOperationType::kMoveConstruction);
expected_ops.emplace_back(2, utils::LifetimeOperationType::kDestruction);
ASSERT_TRUE(p.has_value());
ASSERT_TRUE(tracker.GetOperations() == expected_ops);
}
expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction);
ASSERT_TRUE(tracker.GetOperations() == expected_ops);
}

Expand Down

0 comments on commit deee3c6

Please sign in to comment.