[clang-tools-extra] [clang-tidy] Extend readability-redundant-parentheses to declarations (PR #196739)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Sat May 9 19:49:56 PDT 2026
================
@@ -61,13 +63,33 @@ 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")) {
+ const auto ParenType = TL->getAs<ParenTypeLoc>();
+
+ if (ParenType.isNull())
+ return;
+ const QualType InnerLocType = ParenType.getInnerLoc().getType();
+ if (InnerLocType->isPointerType() || InnerLocType->isReferenceType() ||
+ InnerLocType->isMemberPointerType() || InnerLocType->isFunctionType() ||
+ InnerLocType->isArrayType())
----------------
zwuis wrote:
Please add tests for each condition.
https://github.com/llvm/llvm-project/pull/196739
More information about the cfe-commits
mailing list