[clang-tools-extra] added check for the parentheses declaration (PR #196739)

Omkar Rasal via cfe-commits cfe-commits at lists.llvm.org
Sat May 9 10:40:00 PDT 2026


https://github.com/cs25mtech12008 created https://github.com/llvm/llvm-project/pull/196739

None

>From 696defd512a25ef3ab24a4ad21d02c4220817a1a Mon Sep 17 00:00:00 2001
From: cs25mtech12008 <cs25mtech12008 at iith.ac.in>
Date: Sat, 9 May 2026 23:07:30 +0530
Subject: [PATCH] added check for the parentheses declaration

---
 .../readability/RedundantParenthesesCheck.cpp | 27 ++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
index 9b3948a1c50c0..6d473ccf1c8df 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/AST/TypeLoc.h"
 #include "RedundantParenthesesCheck.h"
 #include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
@@ -61,13 +62,31 @@ void RedundantParenthesesCheck::registerMatchers(MatchFinder *Finder) {
                              hasParent(unaryExprOrTypeTraitExpr()))))
           .bind("dup"),
       this);
+
+  Finder->addMatcher(typeLoc(loc(parenType())).bind("parentheses-decl"), this);
 }
 
 void RedundantParenthesesCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *PE = Result.Nodes.getNodeAs<ParenExpr>("dup");
-  diag(PE->getBeginLoc(), "redundant parentheses around expression")
-      << FixItHint::CreateRemoval(PE->getLParen())
-      << FixItHint::CreateRemoval(PE->getRParen());
+  if (const auto *PE = Result.Nodes.getNodeAs<ParenExpr>("dup")) {
+
+    diag(PE->getBeginLoc(), "redundant parentheses around expression")
+        << FixItHint::CreateRemoval(PE->getLParen())
+        << FixItHint::CreateRemoval(PE->getRParen());
+    return ;
+  }
+
+  if (const auto *TL = Result.Nodes.getNodeAs<TypeLoc>("parentheses-decl")) {
+    ParenTypeLoc ParenType = TL->getAs<ParenTypeLoc>();
+
+    if (ParenType.isNull())
+      return;
+
+    diag(ParenType.getLParenLoc(), "redundant parentheses in declaration")
+        << FixItHint::CreateRemoval(ParenType.getLParenLoc())
+        << FixItHint::CreateRemoval(ParenType.getRParenLoc());
+    return;
+  }
+
 }
 
 } // namespace clang::tidy::readability



More information about the cfe-commits mailing list