https://github.com/zeyi2 updated 
https://github.com/llvm/llvm-project/pull/176565

>From 0c0dbdb004efaa6ae32f47f0de152a6b0424bba4 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 17 Jan 2026 20:27:55 +0800
Subject: [PATCH 1/2] [clang-tidy] Fix modernize-use-using wrongly modifies
 typedef of parenthesized functions

---
 .../clang-tidy/modernize/UseUsingCheck.cpp    | 20 +++++++++++--
 clang-tools-extra/docs/ReleaseNotes.rst       |  4 +++
 .../checkers/modernize/use-using.cpp          | 28 ++++++++++++++++++-
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index 085dbde60db61..d6f422b428c31 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -140,10 +140,24 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
&Result) {
     // without the identifier.
     if (TypeRange.fullyContains(MatchedDecl->getLocation())) {
       FunctionPointerCase = true;
-      const auto RangeLeftOfIdentifier = CharSourceRange::getCharRange(
-          TypeRange.getBegin(), MatchedDecl->getLocation());
+      SourceLocation StartLoc = MatchedDecl->getLocation();
+      SourceLocation EndLoc = MatchedDecl->getLocation();
+
+      while (true) {
+        Token Prev = utils::lexer::getPreviousToken(StartLoc, SM, LO);
+        const std::optional<Token> Next =
+            utils::lexer::findNextTokenSkippingComments(EndLoc, SM, LO);
+        if (Prev.isNot(tok::l_paren) || !Next || Next->isNot(tok::r_paren))
+          break;
+
+        StartLoc = Prev.getLocation();
+        EndLoc = Next->getLocation();
+      }
+
+      const auto RangeLeftOfIdentifier =
+          CharSourceRange::getCharRange(TypeRange.getBegin(), StartLoc);
       const auto RangeRightOfIdentifier = CharSourceRange::getCharRange(
-          Lexer::getLocForEndOfToken(MatchedDecl->getLocation(), 0, SM, LO),
+          Lexer::getLocForEndOfToken(EndLoc, 0, SM, LO),
           Lexer::getLocForEndOfToken(TypeRange.getEnd(), 0, SM, LO));
       const std::string VerbatimType =
           (Lexer::getSourceText(RangeLeftOfIdentifier, SM, LO) +
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 94a11b1acb73a..c3b255d461e01 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -109,6 +109,10 @@ Changes in existing checks
   - Added support for analyzing function parameters with the 
`AnalyzeParameters`
     option.
 
+- Improved :doc:`modernize-use-using
+  <clang-tidy/checks/modernize/use-using>` check by avoiding the generation
+  of invalid code for function types with redundant parentheses.
+
 - Improved :doc:`performance-move-const-arg
   <clang-tidy/checks/performance/move-const-arg>` check by avoiding false
   positives on trivially copyable types with a non-public copy constructor.
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 a1f32b06df091..324616d274646 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
@@ -344,7 +344,7 @@ typedef int InExternCPP;
 }
 
 namespace ISSUE_72179
-{  
+{
   void foo()
   {
     typedef int a;
@@ -461,3 +461,29 @@ namespace GH173732 {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
   // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: use 'using' instead of 
'typedef' [modernize-use-using]
 }
+
+namespace GH176267 {
+  typedef int(f1)(double);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+  // CHECK-FIXES: using f1 = int(double);
+
+  typedef int(f2)(double);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+  // CHECK-FIXES: using f2 = int(double);
+
+  typedef int f3(double);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+  // CHECK-FIXES: using f3 = int (double);
+
+  typedef int (*f4)(double);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+  // CHECK-FIXES: using f4 = int (*)(double);
+
+  typedef int ((f5))(double);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+  // CHECK-FIXES: using f5 = int (double);
+
+  typedef int ( /* comment */ f6 ) (double);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+  // CHECK-FIXES: using f6 = int  (double);
+}

>From 673267fb65eec3ec2989e65dba0f607c7582cd7f Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sat, 17 Jan 2026 20:41:42 +0800
Subject: [PATCH 2/2] Make clang-tidy happy

---
 clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index d6f422b428c31..cc78276e2a8d6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -144,7 +144,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
&Result) {
       SourceLocation EndLoc = MatchedDecl->getLocation();
 
       while (true) {
-        Token Prev = utils::lexer::getPreviousToken(StartLoc, SM, LO);
+        const Token Prev = utils::lexer::getPreviousToken(StartLoc, SM, LO);
         const std::optional<Token> Next =
             utils::lexer::findNextTokenSkippingComments(EndLoc, SM, LO);
         if (Prev.isNot(tok::l_paren) || !Next || Next->isNot(tok::r_paren))

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to