@@ -24,27 +24,28 @@ AST_MATCHER_P(ParenExpr, subExpr, ast_matchers::internal::Matcher<Expr>,
24
24
return InnerMatcher.matches (*Node.getSubExpr (), Finder, Builder);
25
25
}
26
26
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
+
27
33
} // namespace
28
34
29
35
void RedundantParenthesesCheck::registerMatchers (MatchFinder *Finder) {
30
36
Finder->addMatcher (
31
37
parenExpr (subExpr (anyOf (parenExpr (), integerLiteral (), floatLiteral (),
32
38
characterLiteral (), cxxBoolLiteral (),
33
39
stringLiteral (), declRefExpr ())),
34
- unless (
35
- // sizeof(...) is common used.
36
- hasParent (unaryExprOrTypeTraitExpr ())))
40
+ unless (anyOf ( isInMacro (),
41
+ // sizeof(...) is common used.
42
+ hasParent (unaryExprOrTypeTraitExpr () ))))
37
43
.bind (" dup" ),
38
44
this );
39
45
}
40
46
41
47
void RedundantParenthesesCheck::check (const MatchFinder::MatchResult &Result) {
42
48
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 ;
48
49
diag (PE->getBeginLoc (), " redundant parentheses around expression" )
49
50
<< FixItHint::CreateRemoval (PE->getLParen ())
50
51
<< FixItHint::CreateRemoval (PE->getRParen ());
0 commit comments