Skip to content

Commit 42aab95

Browse files
committed
fix review
1 parent 92db784 commit 42aab95

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

clang-tools-extra/clang-tidy/readability/RedundantParenthesesCheck.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@ AST_MATCHER_P(ParenExpr, subExpr, ast_matchers::internal::Matcher<Expr>,
2424
return InnerMatcher.matches(*Node.getSubExpr(), Finder, Builder);
2525
}
2626

27+
AST_MATCHER(ParenExpr, isInMacro) {
28+
const Expr *E = Node.getSubExpr();
29+
return Node.getLParen().isMacroID() || Node.getRParen().isMacroID() ||
30+
E->getBeginLoc().isMacroID() || E->getEndLoc().isMacroID();
31+
}
32+
2733
} // namespace
2834

2935
void RedundantParenthesesCheck::registerMatchers(MatchFinder *Finder) {
3036
Finder->addMatcher(
3137
parenExpr(subExpr(anyOf(parenExpr(), integerLiteral(), floatLiteral(),
3238
characterLiteral(), cxxBoolLiteral(),
3339
stringLiteral(), declRefExpr())),
34-
unless(
35-
// sizeof(...) is common used.
36-
hasParent(unaryExprOrTypeTraitExpr())))
40+
unless(anyOf(isInMacro(),
41+
// sizeof(...) is common used.
42+
hasParent(unaryExprOrTypeTraitExpr()))))
3743
.bind("dup"),
3844
this);
3945
}
4046

4147
void RedundantParenthesesCheck::check(const MatchFinder::MatchResult &Result) {
4248
const auto *PE = Result.Nodes.getNodeAs<ParenExpr>("dup");
43-
assert(PE);
44-
const Expr *E = PE->getSubExpr();
45-
if (PE->getLParen().isMacroID() || PE->getRParen().isMacroID() ||
46-
E->getBeginLoc().isMacroID() || E->getEndLoc().isMacroID())
47-
return;
4849
diag(PE->getBeginLoc(), "redundant parentheses around expression")
4950
<< FixItHint::CreateRemoval(PE->getLParen())
5051
<< FixItHint::CreateRemoval(PE->getRParen());

0 commit comments

Comments
 (0)