Skip to content

Commit 6f7570c

Browse files
authored
[clang-tidy][misc-use-internal-linkage] fix false positives for function or variable in header file which contains macro expansion (#129594)
When check whether in main file, spelling loc will lead to `<scratch space>`. instead, expansion loc is close to loc after preprocess. It is suitable to analyze linkage.
1 parent d08cf79 commit 6f7570c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
5252
static bool isInMainFile(SourceLocation L, SourceManager &SM,
5353
const FileExtensionsSet &HeaderFileExtensions) {
5454
for (;;) {
55-
if (utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions))
55+
if (utils::isExpansionLocInHeaderFile(L, SM, HeaderFileExtensions))
5656
return false;
5757
if (SM.isInMainFile(L))
5858
return true;

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ Changes in existing checks
129129
<clang-tidy/checks/misc/redundant-expression>` check by providing additional
130130
examples and fixing some macro related false positives.
131131

132+
- Improved :doc:`misc-use-internal-linkage
133+
<clang-tidy/checks/misc/use-internal-linkage>` check by fix false positives
134+
for function or variable in header file which contains macro expansion.
135+
132136
- Improved :doc:`performance/unnecessary-value-param
133137
<clang-tidy/checks/performance/unnecessary-value-param>` check performance by
134138
tolerating fix-it breaking compilation when functions is used as pointers
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %check_clang_tidy %s misc-use-internal-linkage %t -- -- -I%S/Inputs/use-internal-linkage
2+
3+
#define B A##C
4+
5+
inline void B() {}

0 commit comments

Comments
 (0)