Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
Checks: "-*,
bugprone-argument-comment
bugprone-argument-comment,
bugprone-use-after-move
"
# bugprone-assert-side-effect,
# bugprone-bad-signal-to-kill-thread,
Expand Down Expand Up @@ -74,7 +75,6 @@ Checks: "-*,
# bugprone-unused-local-non-trivial-variable,
# bugprone-unused-raii,
# bugprone-unused-return-value,
# bugprone-use-after-move,
# bugprone-virtual-near-miss,
# cppcoreguidelines-init-variables,
# cppcoreguidelines-misleading-capture-default-by-value,
Expand Down
4 changes: 4 additions & 0 deletions src/libxrpl/shamap/SHAMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ SHAMap::delItem(uint256 const& id)

node = unshareNode(std::move(node), nodeID);
node->setChild(selectBranch(nodeID, id), std::move(prevNode));
prevNode = intr_ptr::SharedPtr<SHAMapTreeNode>{};
Comment on lines 675 to +677
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reinitializes prevNode immediately after moving it into setChild. Consider using std::exchange(prevNode, {}) as the argument to setChild so the move-and-clear is a single, self-documenting operation and avoids the extra assignment line.

Copilot uses AI. Check for mistakes.

if (!nodeID.isRoot())
{
Expand All @@ -682,6 +683,9 @@ SHAMap::delItem(uint256 const& id)
int const bc = node->getBranchCount();
if (bc == 0)
{
// TODO: looks like this branch is not needed anymore because prevNode is already
// nullptr

// no children below this branch
prevNode.reset();
}
Expand Down
30 changes: 15 additions & 15 deletions src/test/basics/Buffer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ struct Buffer_test : beast::unit_test::suite
{ // Move-construct from empty buf
Buffer x;
Buffer y{std::move(x)};
BEAST_EXPECT(sane(x));
BEAST_EXPECT(x.empty());
BEAST_EXPECT(sane(x)); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(x.empty()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(sane(y));
BEAST_EXPECT(y.empty());
BEAST_EXPECT(x == y);
BEAST_EXPECT(x == y); // NOLINT(bugprone-use-after-move)
}

{ // Move-construct from non-empty buf
Buffer x{b1};
Buffer y{std::move(x)};
BEAST_EXPECT(sane(x));
BEAST_EXPECT(x.empty());
BEAST_EXPECT(sane(x)); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(x.empty()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(sane(y));
BEAST_EXPECT(y == b1);
}
Expand All @@ -129,8 +129,8 @@ struct Buffer_test : beast::unit_test::suite
x = std::move(y);
BEAST_EXPECT(sane(x));
BEAST_EXPECT(x.empty());
BEAST_EXPECT(sane(y));
BEAST_EXPECT(y.empty());
BEAST_EXPECT(sane(y)); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(y.empty()); // NOLINT(bugprone-use-after-move)
}

{ // Move assign non-empty buf to empty buf
Expand All @@ -140,8 +140,8 @@ struct Buffer_test : beast::unit_test::suite
x = std::move(y);
BEAST_EXPECT(sane(x));
BEAST_EXPECT(x == b1);
BEAST_EXPECT(sane(y));
BEAST_EXPECT(y.empty());
BEAST_EXPECT(sane(y)); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(y.empty()); // NOLINT(bugprone-use-after-move)
}

{ // Move assign empty buf to non-empty buf
Expand All @@ -151,8 +151,8 @@ struct Buffer_test : beast::unit_test::suite
x = std::move(y);
BEAST_EXPECT(sane(x));
BEAST_EXPECT(x.empty());
BEAST_EXPECT(sane(y));
BEAST_EXPECT(y.empty());
BEAST_EXPECT(sane(y)); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(y.empty()); // NOLINT(bugprone-use-after-move)
}

{ // Move assign non-empty buf to non-empty buf
Expand All @@ -163,14 +163,14 @@ struct Buffer_test : beast::unit_test::suite
x = std::move(y);
BEAST_EXPECT(sane(x));
BEAST_EXPECT(!x.empty());
BEAST_EXPECT(sane(y));
BEAST_EXPECT(y.empty());
BEAST_EXPECT(sane(y)); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(y.empty()); // NOLINT(bugprone-use-after-move)

x = std::move(z);
BEAST_EXPECT(sane(x));
BEAST_EXPECT(!x.empty());
BEAST_EXPECT(sane(z));
BEAST_EXPECT(z.empty());
BEAST_EXPECT(sane(z)); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(z.empty()); // NOLINT(bugprone-use-after-move)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/core/ClosureCounter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ClosureCounter_test : public beast::unit_test::suite
BEAST_EXPECT(result.copies == 0);
BEAST_EXPECT(result.moves == 1);
BEAST_EXPECT(result.str == "rvalue abcdefghijklmnopqrstuvwxyz!");
BEAST_EXPECT(strRValue.str.size() == 0);
BEAST_EXPECT(strRValue.str.size() == 0); // NOLINT(bugprone-use-after-move)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/jtx/Env_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,14 @@ class Env_test : public beast::unit_test::suite
BEAST_EXPECT(*jt1.get<int>() == 7);
BEAST_EXPECT(!jt1.get<UDT>());
JTx jt2(std::move(jt1));
BEAST_EXPECT(!jt1.get<int>());
BEAST_EXPECT(!jt1.get<UDT>());
BEAST_EXPECT(!jt1.get<int>()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(!jt1.get<UDT>()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(jt2.get<int>());
BEAST_EXPECT(*jt2.get<int>() == 7);
BEAST_EXPECT(!jt2.get<UDT>());
jt1 = std::move(jt2);
BEAST_EXPECT(!jt2.get<int>());
BEAST_EXPECT(!jt2.get<UDT>());
BEAST_EXPECT(!jt2.get<int>()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(!jt2.get<UDT>()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(jt1.get<int>());
BEAST_EXPECT(*jt1.get<int>() == 7);
BEAST_EXPECT(!jt1.get<UDT>());
Expand Down
4 changes: 2 additions & 2 deletions src/test/protocol/STObject_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class STObject_test : public beast::unit_test::suite
Buffer b(1);
BEAST_EXPECT(!b.empty());
st[sf4] = std::move(b);
BEAST_EXPECT(b.empty());
BEAST_EXPECT(b.empty()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(Slice(st[sf4]).size() == 1);
st[~sf4] = std::nullopt;
BEAST_EXPECT(!~st[~sf4]);
Expand All @@ -370,7 +370,7 @@ class STObject_test : public beast::unit_test::suite
BEAST_EXPECT(!!~st[~sf5]);
Buffer b(1);
st[sf5] = std::move(b);
BEAST_EXPECT(b.empty());
BEAST_EXPECT(b.empty()); // NOLINT(bugprone-use-after-move)
BEAST_EXPECT(Slice(st[sf5]).size() == 1);
st[~sf4] = std::nullopt;
BEAST_EXPECT(!~st[~sf4]);
Expand Down
10 changes: 5 additions & 5 deletions src/tests/libxrpl/json/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,16 +761,16 @@ TEST(json_value, move)
EXPECT_EQ(v1.asDouble(), 2.5);

Json::Value v2 = std::move(v1);
EXPECT_FALSE(v1);
EXPECT_FALSE(v1); // NOLINT(bugprone-use-after-move)
EXPECT_TRUE(v2.isDouble());
EXPECT_EQ(v2.asDouble(), 2.5);
EXPECT_NE(v1, v2);
EXPECT_NE(v1, v2); // NOLINT(bugprone-use-after-move)

v1 = std::move(v2);
EXPECT_TRUE(v1.isDouble());
EXPECT_EQ(v1.asDouble(), 2.5);
EXPECT_FALSE(v2);
EXPECT_NE(v1, v2);
EXPECT_FALSE(v2); // NOLINT(bugprone-use-after-move)
EXPECT_NE(v1, v2); // NOLINT(bugprone-use-after-move)
}

TEST(json_value, comparisons)
Expand Down Expand Up @@ -1348,7 +1348,7 @@ TEST(json_value, memory_leak)

// Note that the type() == nullValue check is implementation
// specific and not guaranteed to be valid in the future.
EXPECT_EQ(temp.type(), Json::nullValue);
EXPECT_EQ(temp.type(), Json::nullValue); // NOLINT(bugprone-use-after-move)
}
}

Expand Down
Loading