[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 12 05:23:18 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.h clang-tools-extra/test/clang-tidy/checkers/performance/lost-std-move.cpp clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp b/clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp
index 228d654b3..787580ded 100644
--- a/clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp
@@ -25,7 +25,8 @@ void LostStdMoveCheck::registerMatchers(MatchFinder *Finder) {
hasParent(expr(hasParent(cxxConstructExpr(hasParent(returnStmt())))));
auto outermostExpr = expr(unless(hasParent(expr())));
- auto leafStatement = stmt(outermostExpr, unless(hasDescendant(outermostExpr)));
+ auto leafStatement =
+ stmt(outermostExpr, unless(hasDescendant(outermostExpr)));
Finder->addMatcher(
declRefExpr(
@@ -49,7 +50,7 @@ void LostStdMoveCheck::registerMatchers(MatchFinder *Finder) {
unless(hasDeclaration(
varDecl(hasType(qualType(lValueReferenceType()))))),
- hasAncestor(leafStatement.bind("leaf_statement")),
+ hasAncestor(leafStatement.bind("leaf_statement")),
hasDeclaration(
varDecl(hasAncestor(functionDecl().bind("func"))).bind("decl")),
@@ -88,7 +89,8 @@ void LostStdMoveCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedFunc = Result.Nodes.getNodeAs<FunctionDecl>("func");
const auto *MatchedUse = Result.Nodes.getNodeAs<Expr>("use");
const auto *MatchedUseCall = Result.Nodes.getNodeAs<CallExpr>("use_parent");
- const auto *MatchedLeafStatement = Result.Nodes.getNodeAs<Stmt>("leaf_statement");
+ const auto *MatchedLeafStatement =
+ Result.Nodes.getNodeAs<Stmt>("leaf_statement");
if (MatchedUseCall)
return;
@@ -105,7 +107,9 @@ void LostStdMoveCheck::check(const MatchFinder::MatchResult &Result) {
// Calculate X usage count in the statement
llvm::SmallPtrSet<const DeclRefExpr *, 16> DeclRefs;
- auto Matches = match(findAll(declRefExpr(to(varDecl(equalsNode(MatchedDecl)))).bind("ref")), *MatchedLeafStatement, *Result.Context);
+ auto Matches = match(
+ findAll(declRefExpr(to(varDecl(equalsNode(MatchedDecl)))).bind("ref")),
+ *MatchedLeafStatement, *Result.Context);
extractNodesByIdTo(Matches, "ref", DeclRefs);
if (DeclRefs.size() > 1) {
// Unspecified order of evaluation, e.g. f(x, x)
``````````
</details>
https://github.com/llvm/llvm-project/pull/139525
More information about the cfe-commits
mailing list