Skip to content

Commit a27b1b3

Browse files
committed
better test
1 parent 60e4aca commit a27b1b3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ void f_extern()
6262
f(ptr);
6363
}
6464

65+
std::shared_ptr<int> global;
66+
void f_global()
67+
{
68+
f(global);
69+
}
70+
6571
void f_local()
6672
{
6773
std::shared_ptr<int> ptr;
@@ -140,3 +146,36 @@ int f_macro()
140146
std::shared_ptr<int> ptr;
141147
return FUN(ptr);
142148
}
149+
150+
void f_lambda_ref()
151+
{
152+
std::shared_ptr<int> ptr;
153+
auto Lambda = [&ptr]() mutable {
154+
f(ptr);
155+
};
156+
Lambda();
157+
}
158+
159+
void f_lambda()
160+
{
161+
std::shared_ptr<int> ptr;
162+
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.
166+
f(ptr);
167+
};
168+
Lambda();
169+
}
170+
171+
void f_lambda_assign()
172+
{
173+
std::shared_ptr<int> ptr;
174+
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.
178+
f(ptr);
179+
};
180+
Lambda();
181+
}

0 commit comments

Comments
 (0)