Skip to content

Commit 60e4aca

Browse files
committed
thread_local, extern, static
1 parent b4824ef commit 60e4aca

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void LostStdMoveCheck::check(const MatchFinder::MatchResult& Result) {
117117
const auto* MatchedLeafStatement =
118118
Result.Nodes.getNodeAs<Stmt>("leaf_statement");
119119

120+
if (!MatchedDecl->hasLocalStorage()) return;
121+
120122
if (MatchedUseCall) {
121123
return;
122124
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ void f_using(SharedPtr ptr)
4141
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
4242
}
4343

44+
void f_thread_local()
45+
{
46+
thread_local std::shared_ptr<int> ptr;
47+
if (*ptr)
48+
f(ptr);
49+
}
50+
51+
void f_static()
52+
{
53+
static std::shared_ptr<int> ptr;
54+
if (*ptr)
55+
f(ptr);
56+
}
57+
58+
void f_extern()
59+
{
60+
extern std::shared_ptr<int> ptr;
61+
if (*ptr)
62+
f(ptr);
63+
}
64+
4465
void f_local()
4566
{
4667
std::shared_ptr<int> ptr;
@@ -112,3 +133,10 @@ int f_multiple_usages()
112133
std::shared_ptr<int> ptr;
113134
return f(ptr) + f(ptr);
114135
}
136+
137+
#define FUN(x) f((x))
138+
int f_macro()
139+
{
140+
std::shared_ptr<int> ptr;
141+
return FUN(ptr);
142+
}

0 commit comments

Comments
 (0)