Kaydet (Commit) e4faf550 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

lopgluin:unnecessaryparen: Properly treat parenthesized sub-expr in sizeof (x)

...where redundant parentheses are probably common enough to not warn about them

Change-Id: Ia88097f5d3433e03337d6d42a144abfe210733c2
üst 8c8894ec
......@@ -61,15 +61,20 @@ public:
bool TraverseConditionalOperator(ConditionalOperator *);
private:
void VisitSomeStmt(const Stmt *parent, const Expr* cond, StringRef stmtName);
Expr* insideSizeof = nullptr;
Expr* insideCaseStmt = nullptr;
Expr* insideConditionalOperator = nullptr;
};
bool UnnecessaryParen::TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *)
bool UnnecessaryParen::TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr * expr)
{
// for some reason, the parentheses in an expression like "sizeof(x)" actually show up
// in the AST, so just ignore that part of the AST
return true;
auto old = insideSizeof;
if (expr->getKind() == UETT_SizeOf && !expr->isArgumentType()) {
insideSizeof = expr->getArgumentExpr()->IgnoreImpCasts();
}
bool ret = RecursiveASTVisitor::TraverseUnaryExprOrTypeTraitExpr(expr);
insideSizeof = old;
return ret;
}
bool UnnecessaryParen::TraverseCaseStmt(CaseStmt * caseStmt)
......@@ -96,6 +101,8 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr)
return true;
if (parenExpr->getLocStart().isMacroID())
return true;
if (insideSizeof && parenExpr == insideSizeof)
return true;
if (insideCaseStmt && parenExpr == insideCaseStmt)
return true;
if (insideConditionalOperator && parenExpr == insideConditionalOperator)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment