Skip to content

Commit 6aacd41

Browse files
committed
fixes
1 parent a27b1b3 commit 6aacd41

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void extractNodesByIdTo(ArrayRef<BoundNodes> Matches, StringRef ID,
2121
Nodes.insert(Match.getNodeAs<Node>(ID));
2222
}
2323

24-
llvm::SmallPtrSet<const DeclRefExpr*, 16> allDeclRefExprsHonourLambda(
24+
static llvm::SmallPtrSet<const DeclRefExpr*, 16> allDeclRefExprsHonourLambda(
2525
const VarDecl& VarDecl, const Decl& Decl, ASTContext& Context) {
2626
auto Matches = match(
2727
decl(forEachDescendant(
@@ -84,6 +84,9 @@ void LostStdMoveCheck::registerMatchers(MatchFinder* Finder) {
8484

8585
unless(hasAncestor(whileStmt())),
8686

87+
// Not in a body of lambda
88+
unless(hasAncestor(compoundStmt(hasAncestor(lambdaExpr())))),
89+
8790
// only non-X&
8891
unless(hasDeclaration(
8992
varDecl(hasType(qualType(lValueReferenceType()))))),

clang-tools-extra/test/clang-tidy/checkers/performance/lost-std-move.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ void f_arg(std::shared_ptr<int> ptr)
2424
if (*ptr)
2525
f(ptr);
2626
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
27+
// CHECK-FIXES: f(std::move(ptr));
2728
}
2829

2930
void f_rvalue_ref(std::shared_ptr<int>&& ptr)
3031
{
3132
if (*ptr)
3233
f(ptr);
3334
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
35+
// CHECK-FIXES: f(std::move(ptr));
3436
}
3537

3638
using SharedPtr = std::shared_ptr<int>;
@@ -74,6 +76,7 @@ void f_local()
7476
if (*ptr)
7577
f(ptr);
7678
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
79+
// CHECK-FIXES: f(std::move(ptr));
7780
}
7881

7982
void f_move()
@@ -131,7 +134,7 @@ void f_cycle4()
131134
std::shared_ptr<int> ptr;
132135
do {
133136
f(ptr);
134-
} while (*ptr);
137+
} while (true);
135138
}
136139

137140
int f_multiple_usages()
@@ -145,6 +148,8 @@ int f_macro()
145148
{
146149
std::shared_ptr<int> ptr;
147150
return FUN(ptr);
151+
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: could be std::move() [performance-lost-std-move]
152+
// CHECK-FIXES: return FUN(std::move(ptr));
148153
}
149154

150155
void f_lambda_ref()
@@ -160,9 +165,8 @@ void f_lambda()
160165
{
161166
std::shared_ptr<int> ptr;
162167
auto Lambda = [ptr]() mutable {
163-
// CHECK-MESSAGES: [[@LINE-1]]:18: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
164-
// CHECK-FIXES: auto Lambda = [Mov]() mutable {
165-
// Note: No fix, because a fix requires c++14.
168+
// CHECK-MESSAGES: [[@LINE-1]]:18: warning: could be std::move() [performance-lost-std-move]
169+
// CHECK-FIXES: auto Lambda = [std::move(ptr)]() mutable {
166170
f(ptr);
167171
};
168172
Lambda();
@@ -172,9 +176,8 @@ void f_lambda_assign()
172176
{
173177
std::shared_ptr<int> ptr;
174178
auto Lambda = [ptr = ptr]() mutable {
175-
// CHECK-MESSAGES: [[@LINE-1]]:18: warning: Parameter 'Mov' is copied on last use, consider moving it instead. [performance-unnecessary-copy-on-last-use]
176-
// CHECK-FIXES: auto Lambda = [Mov]() mutable {
177-
// Note: No fix, because a fix requires c++14.
179+
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: could be std::move() [performance-lost-std-move]
180+
// CHECK-FIXES: auto Lambda = [ptr = std::move(ptr)]() mutable {
178181
f(ptr);
179182
};
180183
Lambda();

0 commit comments

Comments
 (0)