Skip to content

Commit ee966ce

Browse files
author
huqizhi
committed
[clang-tidy]: Add TagDecl into LastTagDeclRanges in UseUsingCheck only when it is a definition
1 parent f9558c6 commit ee966ce

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
6161
// before the typedef will be the nested one (PR#50990). Therefore, we also
6262
// keep track of the parent declaration, so that we can look up the last
6363
// TagDecl that is a sibling of the typedef in the AST.
64-
LastTagDeclRanges[ParentDecl] = MatchedTagDecl->getSourceRange();
64+
if (MatchedTagDecl->isThisDeclarationADefinition())
65+
LastTagDeclRanges[ParentDecl] = MatchedTagDecl->getSourceRange();
6566
return;
6667
}
6768

clang-tools-extra/docs/ReleaseNotes.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ Changes in existing checks
279279
fixes for reordering arguments.
280280

281281
- Improved :doc:`modernize-use-using
282-
<clang-tidy/checks/modernize/use-using>` check to fix function pointer
283-
``typedef`` correctly.
282+
<clang-tidy/checks/modernize/use-using>` check to fix function pointer and
283+
forward declared ``typedef`` correctly.
284284

285285
- Improved :doc:`performance-faster-string-find
286286
<clang-tidy/checks/performance/faster-string-find>` check to properly escape

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,7 @@ typedef bool (*ISSUE_65055_2)(int);
321321
// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use 'using' instead of 'typedef'
322322
// CHECK-FIXES: {{^}}using ISSUE_65055_1 = void (*)(int);{{$}}
323323
// CHECK-FIXES: {{^}}using ISSUE_65055_2 = bool (*)(int);{{$}}
324+
325+
typedef class ISSUE_67529_1 *ISSUE_67529;
326+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
327+
// CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;

0 commit comments

Comments
 (0)