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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Feb 20 10:15:22 UTC 2019


 compilerplugins/clang/indentation.cxx      |    7 +++++++
 compilerplugins/clang/test/indentation.cxx |    7 +++++++
 2 files changed, 14 insertions(+)

New commits:
commit 0626e66d761de18f62e4d00d427903032da9d517
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Feb 19 21:09:29 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Feb 20 11:14:55 2019 +0100

    Avoid loplugin:indentation after preproc conditional inclusion lines
    
    ...to not trigger (for --disable-dbgutil) at
    
    >                         rContentAtPos.eContentAtPos = IsAttrAtPos::TableBoxFml;
    > #ifdef DBG_UTIL
    >                         if( RES_BOXATR_VALUE == pItem->Which() )
    >                             rContentAtPos.eContentAtPos = IsAttrAtPos::TableBoxValue;
    >                         else
    > #endif
    >                             const_cast<SwTableBoxFormula*>(static_cast<const SwTableBoxFormula*>(pItem))->PtrToBoxNm( &pTableNd->GetTable() );
    
    (sw/source/core/crsr/crstrvl.cxx:1710)
    
    Change-Id: I8fd5c8a1cd40450bdd8cc97057e5233a0134f044
    Reviewed-on: https://gerrit.libreoffice.org/68030
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/indentation.cxx b/compilerplugins/clang/indentation.cxx
index 04a9be6677d0..deac18121443 100644
--- a/compilerplugins/clang/indentation.cxx
+++ b/compilerplugins/clang/indentation.cxx
@@ -86,10 +86,13 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt)
     Stmt const* firstStmt = nullptr;
     unsigned curLine = MAX;
     unsigned prevLine = MAX;
+    SourceLocation prevEnd;
     auto& SM = compiler.getSourceManager();
     for (auto i = compoundStmt->body_begin(); i != compoundStmt->body_end(); ++i)
     {
         auto stmt = *i;
+        auto const actualPrevEnd = prevEnd;
+        prevEnd = compat::getEndLoc(stmt); // compute early, before below `continue`s
 
         // these show up in macro expansions, not interesting
         if (isa<NullStmt>(stmt))
@@ -158,6 +161,10 @@ bool Indentation::VisitCompoundStmt(CompoundStmt const* compoundStmt)
         }
         else if (column != tmpColumn)
         {
+            if (containsPreprocessingConditionalInclusion(SourceRange(
+                    locationAfterToken(compiler.getSourceManager().getExpansionLoc(actualPrevEnd)),
+                    compiler.getSourceManager().getExpansionLoc(compat::getBeginLoc(stmt)))))
+                continue;
             report(DiagnosticsEngine::Warning, "statement mis-aligned compared to neighbours %0",
                    stmtLoc)
                 << macroName;
diff --git a/compilerplugins/clang/test/indentation.cxx b/compilerplugins/clang/test/indentation.cxx
index b313fff1fe62..f7cccce67cc5 100644
--- a/compilerplugins/clang/test/indentation.cxx
+++ b/compilerplugins/clang/test/indentation.cxx
@@ -35,6 +35,13 @@ void top1(int x) {
         case 1: foo(); break; // 1expected-note {{measured against this one [loplugin:indentation]}}
          case 2: foo(); break; // 1expected-error {{statement mis-aligned compared to neighbours [loplugin:indentation]}}
     };
+
+#if 0
+    if (x)
+        foo();
+    else
+#endif
+        foo();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */


More information about the Libreoffice-commits mailing list