compilerplugins/clang/unnecessaryparen.cxx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
New commits: commit e4faf5502db93af263c7c746f6e79cbb185b1644 Author: Stephan Bergmann <sberg...@redhat.com> Date: Sun Jul 16 20:35:11 2017 +0200 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 diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx index 94bd9b720852..4abfd69e3b7c 100644 --- a/compilerplugins/clang/unnecessaryparen.cxx +++ b/compilerplugins/clang/unnecessaryparen.cxx @@ -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) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits