[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](https://github.com/llvm/llvm-project/issues/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 <836744285@qq.com>
This commit is contained in:
Qizhi Hu 2023-10-05 13:49:21 +08:00 committed by GitHub
parent a4765c6a02
commit eef35c287e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

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

View File

@ -279,8 +279,8 @@ Changes in existing checks
fixes for reordering arguments.
- Improved :doc:`modernize-use-using
<clang-tidy/checks/modernize/use-using>` check to fix function pointer
``typedef`` correctly.
<clang-tidy/checks/modernize/use-using>` check to fix function pointer and
forward declared ``typedef`` correctly.
- Improved :doc:`performance-faster-string-find
<clang-tidy/checks/performance/faster-string-find>` check to properly escape

View File

@ -321,3 +321,7 @@ typedef bool (*ISSUE_65055_2)(int);
// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use 'using' instead of 'typedef'
// CHECK-FIXES: {{^}}using ISSUE_65055_1 = void (*)(int);{{$}}
// CHECK-FIXES: {{^}}using ISSUE_65055_2 = bool (*)(int);{{$}}
typedef class ISSUE_67529_1 *ISSUE_67529;
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
// CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;