Skip to content

Commit eef35c2

Browse files
authored
[clang-tidy]: Add TagDecl into LastTagDeclRanges in UseUsingCheck only when it is a definition (#67639)
Fix issue 67529, [clang-tidy: modernize-use-using fails when type is implicitly forward declared](#67529) The problem is that using `Lexer` to get record declaration will lose the type information when its original type is pointer or reference. This patch fix this problem by skip adding the tag declaration when it's only a 'declaration' and not a 'definition'. Co-authored-by: huqizhi <[email protected]>
1 parent a4765c6 commit eef35c2

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 0 deletions
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)