[clang-tools-extra] [clang-tidy]: Add TagDecl only when it is a definition && Fix issue 6… (PR #67639)

Qizhi Hu via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 28 00:37:56 PDT 2023


https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/67639

Fix issue 67529, [clang-tidy: modernize-use-using fails when type is implicitly forward declared](https://github.com/llvm/llvm-project/issues/67529)

>From ce645a61b73005a90cc7a0d2cdded632dd047b08 Mon Sep 17 00:00:00 2001
From: huqizhi <huqizhi at feysh.com>
Date: Thu, 28 Sep 2023 15:35:35 +0800
Subject: [PATCH] [clang-tidy]: Add TagDecl only when it is a definition && Fix
 issue 67529

---
 clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp      | 3 ++-
 .../test/clang-tidy/checkers/modernize/use-using.cpp          | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index 22dc9e21cab9d5a..e6293ed48bfddbb 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -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;
   }
 
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index f7db0af6434ac42..422abee11a71962 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -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 *;



More information about the cfe-commits mailing list