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

Stephan Bergmann sbergman at redhat.com
Thu Oct 5 07:38:57 UTC 2017


 compilerplugins/clang/flatten.cxx      |   11 ++++-------
 compilerplugins/clang/test/flatten.cxx |    9 ++++++---
 2 files changed, 10 insertions(+), 10 deletions(-)

New commits:
commit 3d1b53a0998659e6a75def21d2b539c692168149
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Sat Sep 30 22:39:33 2017 +0200

    Also suppress loplugin:flatten in C++ class member functions...
    
    ...invovling preprocessing conditionals, to actually make the unhelpful warning
    on Windows about OleEmbeddedObject::changeState go away.  And while at it, make
    the check for preprocessing conditionals more targeted (similar to
    1084e8be44661aaeacb8801707701013eb3fcdbc "More targeted check for preprocessing
    conditionals in loplugin:blockblock").
    
    Change-Id: I0300e0a547e969520a90cd126ea8f788cc17560f
    Reviewed-on: https://gerrit.libreoffice.org/42975
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/flatten.cxx b/compilerplugins/clang/flatten.cxx
index 1dd265990cb7..7fa408ea1731 100644
--- a/compilerplugins/clang/flatten.cxx
+++ b/compilerplugins/clang/flatten.cxx
@@ -30,13 +30,6 @@ public:
         TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
     }
 
-    bool TraverseFunctionDecl(FunctionDecl * decl) {
-        if (containsPreprocessingConditionalInclusion(decl->getSourceRange())) {
-            return true;
-        }
-        return RecursiveASTVisitor::TraverseFunctionDecl(decl);
-    }
-
     bool TraverseCXXCatchStmt(CXXCatchStmt * );
     bool VisitIfStmt(IfStmt const * );
 private:
@@ -115,6 +108,10 @@ bool Flatten::VisitIfStmt(IfStmt const * ifStmt)
     if (parentIfStmt && parentIfStmt->getElse() == ifStmt)
         return true;
 
+    if (containsPreprocessingConditionalInclusion(ifStmt->getSourceRange())) {
+        return true;
+    }
+
     auto throwExpr = containsSingleThrowExpr(ifStmt->getElse());
     if (throwExpr)
     {
diff --git a/compilerplugins/clang/test/flatten.cxx b/compilerplugins/clang/test/flatten.cxx
index 91321276c45e..a901d273b9a1 100644
--- a/compilerplugins/clang/test/flatten.cxx
+++ b/compilerplugins/clang/test/flatten.cxx
@@ -56,13 +56,16 @@ void top4() {
 }
 
 void top5() {
-    // no warning expected
 #if 1
     if (foo() == 2) {
-        bar();
+        if (foo() == 3) { // expected-note {{if condition here [loplugin:flatten]}}
+            bar();
+        } else {
+            throw std::exception(); // expected-error {{unconditional throw in else branch, rather invert the condition, throw early, and flatten the normal case [loplugin:flatten]}}
+        }
     } else
 #endif
-        throw std::exception();
+        throw std::exception(); // no warning expected
 }
 
 int main() {


More information about the Libreoffice-commits mailing list