[clang-tools-extra] added check for the parentheses declaration (PR #196739)
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 9 10:40:52 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Omkar Rasal (cs25mtech12008)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/196739.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp (+23-4)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/196739
More information about the cfe-commits
mailing list