Sponsored Content
Skip to content

chore: Enable clang-tidy bugprone-use-after-move check - #6476

Merged
bthomee merged 20 commits into
XRPLF:developfrom
godexsoft:chore/clang-tidy-checks-bugprone-use-after-move
Mar 18, 2026
Merged

chore: Enable clang-tidy bugprone-use-after-move check#6476
bthomee merged 20 commits into
XRPLF:developfrom
godexsoft:chore/clang-tidy-checks-bugprone-use-after-move

Conversation

@godexsoft

Copy link
Copy Markdown
Contributor

High Level Overview of Change

This PR enables clang-tidy bugprone-use-after-move check.

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

API Impact

No impact.

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@godexsoft godexsoft added the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Mar 4, 2026
@codecov

codecov Bot commented Mar 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.8%. Comparing base (9e14707) to head (76df614).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
src/libxrpl/shamap/SHAMap.cpp 83.3% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #6476     +/-   ##
=========================================
- Coverage     79.8%   79.8%   -0.0%     
=========================================
  Files          878     878             
  Lines        68026   68028      +2     
  Branches      7556    7555      -1     
=========================================
- Hits         54309   54302      -7     
- Misses       13717   13726      +9     
Files with missing lines Coverage Δ
src/libxrpl/shamap/SHAMap.cpp 91.4% <83.3%> (+<0.1%) ⬆️

... and 2 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@godexsoft godexsoft removed the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Mar 9, 2026
@godexsoft
godexsoft marked this pull request as ready for review March 9, 2026 15:12

@godexsoft godexsoft left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems like an old .reset() might not be needed anymore. @ximinez if you could take a look and advise, would be great.

Comment thread src/libxrpl/shamap/SHAMap.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Enables the clang-tidy bugprone-use-after-move check and updates existing code/tests to accommodate the new diagnostic by adding targeted suppressions where moved-from state is intentionally inspected.

Changes:

  • Enable bugprone-use-after-move in .clang-tidy.
  • Add // NOLINT(bugprone-use-after-move) suppressions in multiple unit tests that intentionally validate moved-from behavior.
  • Add a suppression (and TODO) in SHAMap::delItem around a moved-from pointer reset.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
.clang-tidy Turns on bugprone-use-after-move check.
src/tests/libxrpl/json/Value.cpp Suppresses intentional moved-from inspections in JSON value tests.
src/test/protocol/STObject_test.cpp Suppresses moved-from Buffer checks after move into STObject.
src/test/jtx/Env_test.cpp Suppresses moved-from JTx state checks in move tests.
src/test/core/ClosureCounter_test.cpp Suppresses moved-from string state check after forwarding/move.
src/test/basics/Buffer_test.cpp Suppresses moved-from Buffer validation in move construction/assignment tests.
src/libxrpl/shamap/SHAMap.cpp Suppresses a use-after-move warning on prevNode.reset() in delItem.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/libxrpl/shamap/SHAMap.cpp Outdated

@ximinez ximinez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm only flagging this as "request changes" to point out this comment: #6476 (comment)

Otherwise, this looks fine.

@godexsoft
godexsoft requested a review from ximinez March 10, 2026 17:46

@ximinez ximinez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The updates look good, but I did have an alternative suggestion below. Whether it works or not, if you make the change or not, just re-request, and I'll approve.

Comment on lines 684 to 688
{
// no children below this branch
prevNode.reset();
XRPL_ASSERT(
not prevNode, // NOLINT(bugprone-use-after-move)
"xrpl::SHAMap::delItem : There should be no children below this branch");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm looking fresh at the context around this change. It's in a loop and prevNode is reused on each iteration. I didn't notice that before. The old reset() is ensuring that prevNode is holding a nullptr for the next loop, juuuust in case the std::move doesn't do what we expect. But that upsets the linter. OTOH, the assignments below do not upset the linter. Have you tried doing a direct assignment like the ones below? prevNode = nullptr; or prevNode = intr_ptr::SharedPtr<SHAMapTreeNode>{}?

If that works, I think that would be a safer way to go. You can move or remove the assert.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's try! In less critical code i would say this is redundant but it's SHAMap so I'll do anything to stay safe here 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line attracted my attention too. After reviewing reset() vs operator=(SharedIntrusive&&), the assignment is technically redundant—move semantics already guarantee prevNode.ptr_ becomes nullptr via unsafeExchange(nullptr).

That said, I'm fine keeping it for code clarity. The explicit assignment prevNode = TreeNodeType{} makes the intent obvious to readers who aren't familiar with SharedIntrusive internals, even though it performs no actual refcount operations (the null check in unsafeReleaseAndStore causes an early return).

Not a safety issue, just a style preference for defensive clarity.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] Another alternative would be to use std::exchange here:

node->setChild(                                                                                                                                 
    selectBranch(nodeID, id),
    std::exchange(prevNode, TreeNodeType{}));

This keeps the explicit reset while avoiding the moved-from state entirely, which allows
removing the // NOLINT(bugprone-use-after-move) suppression.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree with your assessment and I too think that this is a good alternative. But i'm somewhat hesitant to touch SHAMap code in general so prefer to leave the ASSERT and explicit assignment at this time 👍

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@vlntb is this something you could pick in as a follow-up PR, given you're much more familiar with the SHAMap?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, it requires both SHAMap and intrusive pointers knowledge - I'm happy to do a follow-up on this, even if it is not an essential change.

@godexsoft
godexsoft requested a review from ximinez March 16, 2026 16:06
@godexsoft
godexsoft requested a review from bthomee March 16, 2026 16:08
@bthomee
bthomee requested review from vlntb and removed request for bthomee March 17, 2026 14:16

@vlntb vlntb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Added an optional suggestion.

@godexsoft godexsoft added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Mar 17, 2026
@bthomee
bthomee enabled auto-merge (squash) March 17, 2026 23:52
@bthomee
bthomee merged commit 2a325e7 into XRPLF:develop Mar 18, 2026
1 check passed
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants