Skip to content

Commit

Permalink
Merge pull request #4202 from randombit/fix/scoped_cleanup
Browse files Browse the repository at this point in the history
FIX: move() of scoped_cleanup
  • Loading branch information
reneme authored Jul 12, 2024
2 parents 2bc1985 + 4e05de7 commit d88042e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/lib/utils/stl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,16 @@ class scoped_cleanup {

scoped_cleanup(const scoped_cleanup&) = delete;
scoped_cleanup& operator=(const scoped_cleanup&) = delete;
scoped_cleanup(scoped_cleanup&&) = default;
scoped_cleanup& operator=(scoped_cleanup&&) = default;

scoped_cleanup(scoped_cleanup&& other) : m_cleanup(std::move(other.m_cleanup)) { other.disengage(); }

scoped_cleanup& operator=(scoped_cleanup&& other) {
if(this != &other) {
m_cleanup = std::move(other.m_cleanup);
other.disengage();
}
return *this;
}

~scoped_cleanup() {
if(m_cleanup.has_value()) {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,8 @@ class UUID_Tests : public Test {

BOTAN_REGISTER_TEST("utils", "uuid", UUID_Tests);

#endif

class Formatter_Tests : public Test {
public:
std::vector<Test::Result> run() override {
Expand Down Expand Up @@ -1323,8 +1325,6 @@ class ScopedCleanup_Tests : public Test {

BOTAN_REGISTER_TEST("utils", "scoped_cleanup", ScopedCleanup_Tests);

#endif

} // namespace

} // namespace Botan_Tests

0 comments on commit d88042e

Please sign in to comment.