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

Stephan Bergmann sbergman at redhat.com
Sat Sep 30 11:29:12 UTC 2017


 compilerplugins/clang/flatten.cxx      |    7 +++++++
 compilerplugins/clang/test/flatten.cxx |   10 ++++++++++
 2 files changed, 17 insertions(+)

New commits:
commit 62274b24f91952cf98d387333684d9e874a6b75e
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Sat Sep 30 10:40:32 2017 +0200

    Suppress loplugin:flatten in functions involving preprocessing conditionals
    
    ...as needed by clang-cl on Windows to avoid unhelpful warnings about
    OleEmbeddedObject::changeState (embeddedobj/source/msole/oleembed.cxx)
    containging an "if" in an "#ifdef _WIN32" block followed by "else throw".
    
    Change-Id: I95bed29b9003db08499156ae7f885aeeea5a0158
    Reviewed-on: https://gerrit.libreoffice.org/42963
    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 dd7afa44d068..1dd265990cb7 100644
--- a/compilerplugins/clang/flatten.cxx
+++ b/compilerplugins/clang/flatten.cxx
@@ -30,6 +30,13 @@ 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:
diff --git a/compilerplugins/clang/test/flatten.cxx b/compilerplugins/clang/test/flatten.cxx
index 8d745b16ad45..91321276c45e 100644
--- a/compilerplugins/clang/test/flatten.cxx
+++ b/compilerplugins/clang/test/flatten.cxx
@@ -55,6 +55,16 @@ void top4() {
     (void)x;
 }
 
+void top5() {
+    // no warning expected
+#if 1
+    if (foo() == 2) {
+        bar();
+    } else
+#endif
+        throw std::exception();
+}
+
 int main() {
     // no warning expected
     if (bar() == 3) {


More information about the Libreoffice-commits mailing list