Skip to content

Commit 3bbd80f

Browse files
committed
[clang-tidy] Remove thread local variables from matching
1 parent a27da0a commit 3bbd80f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) {
130130
isMain())))
131131
.bind("fn"),
132132
this);
133-
Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this);
133+
Finder->addMatcher(
134+
varDecl(Common, hasGlobalStorage(), unless(hasThreadStorageDuration()))
135+
.bind("var"),
136+
this);
134137
}
135138

136139
static constexpr StringRef Message =

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ Changes in existing checks
164164

165165
- Improved :doc:`misc-use-internal-linkage
166166
<clang-tidy/checks/misc/use-internal-linkage>` check by fix false positives
167-
for function or variable in header file which contains macro expansion.
167+
for function or variable in header file which contains macro expansion and
168+
excluding variables with ``thread_local`` storage class specifier from being
169+
matched.
168170

169171
- Improved :doc:`modernize-use-default-member-init
170172
<clang-tidy/checks/modernize/use-default-member-init>` check by matching

clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ extern int global_extern;
3131

3232
static int global_static;
3333

34+
thread_local int global_thread_local;
35+
3436
namespace {
3537
static int global_anonymous_ns;
3638
namespace NS {
@@ -41,6 +43,7 @@ static int global_anonymous_ns;
4143
static void f(int para) {
4244
int local;
4345
static int local_static;
46+
thread_local int local_thread_local;
4447
}
4548

4649
struct S {

0 commit comments

Comments
 (0)