[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann sbergman at redhat.com
Sun Jul 16 18:37:48 UTC 2017


 compilerplugins/clang/unnecessaryparen.cxx |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

New commits:
commit e4faf5502db93af263c7c746f6e79cbb185b1644
Author: Stephan Bergmann <sbergman at 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)


More information about the Libreoffice-commits mailing list