compilerplugins/clang/fakebool.cxx |   57 +++++--------------------------------
 cppu/qa/test_any.cxx               |   20 ++++++++++++
 cppu/source/uno/check.cxx          |    5 +++
 3 files changed, 33 insertions(+), 49 deletions(-)

New commits:
commit 5b6bc8182bc1586facca5c3a019c9985e0d7b411
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Fri Apr 29 11:08:37 2022 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Fri Apr 29 13:09:40 2022 +0200

    Use the false warning suppression mechanism for loplugin:fakebool
    
    Change-Id: I6572e500edc1be845c28389b0a4d3ca258dbbecb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133593
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/compilerplugins/clang/fakebool.cxx 
b/compilerplugins/clang/fakebool.cxx
index 3d5120153d0b..80efa55bd432 100644
--- a/compilerplugins/clang/fakebool.cxx
+++ b/compilerplugins/clang/fakebool.cxx
@@ -213,8 +213,6 @@ public:
 
     bool VisitValueDecl(ValueDecl const * decl);
 
-    bool TraverseStaticAssertDecl(StaticAssertDecl * decl);
-
     bool TraverseLinkageSpecDecl(LinkageSpecDecl * decl);
 
 private:
@@ -222,8 +220,6 @@ private:
 
     bool isSharedCAndCppCode(SourceLocation location) const;
 
-    bool isInSpecialMainFile(SourceLocation spellingLocation) const;
-
     bool rewrite(SourceLocation location, FakeBoolKind kind);
 
     std::map<VarDecl const *, FakeBoolKind> varDecls_;
@@ -270,7 +266,7 @@ void FakeBool::run() {
                     }
                 }
             }
-            if (!rewrite(loc, fbk)) {
+            if (!(suppressWarningAt(loc) || rewrite(loc, fbk))) {
                 report(
                     DiagnosticsEngine::Warning,
                     "VarDecl, use \"bool\" instead of %0", loc)
@@ -312,7 +308,7 @@ void FakeBool::run() {
                     }
                 }
             }
-            if (!rewrite(loc, fbk)) {
+            if (!(suppressWarningAt(loc) || rewrite(loc, fbk))) {
                 report(
                     DiagnosticsEngine::Warning,
                     "FieldDecl, use \"bool\" instead of %0", loc)
@@ -561,6 +557,9 @@ bool FakeBool::VisitCStyleCastExpr(CStyleCastExpr * expr) {
                         // arguments to CPPUNIT_ASSERT_EQUAL:
                         return true;
                     }
+                    if (suppressWarningAt(callLoc)) {
+                        return true;
+                    }
                     bool b = k == FBK_sal_Bool && name == "sal_True";
                     if (rewriter != nullptr) {
                         auto callSpellLoc = compiler.getSourceManager()
@@ -603,14 +602,10 @@ bool FakeBool::VisitCXXStaticCastExpr(CXXStaticCastExpr * 
expr) {
     if (ignoreLocation(expr)) {
         return true;
     }
-    auto const k = isFakeBool(expr->getType());
-    if (k == FBK_No) {
+    if (isFakeBool(expr->getType()) == FBK_No) {
         return true;
     }
-    if (k == FBK_sal_Bool
-        && isInSpecialMainFile(
-            compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())))
-    {
+    if (suppressWarningAt(expr->getBeginLoc())) {
         return true;
     }
     report(
@@ -777,14 +772,7 @@ bool FakeBool::VisitVarDecl(VarDecl const * decl) {
     if (k == FBK_No) {
         return true;
     }
-    auto const loc = decl->getBeginLoc();
-    if (k == FBK_sal_Bool
-        && isInSpecialMainFile(
-            compiler.getSourceManager().getSpellingLoc(loc)))
-    {
-        return true;
-    }
-    auto l = loc;
+    auto l = decl->getBeginLoc();
     while (compiler.getSourceManager().isMacroArgExpansion(l)) {
         l = compiler.getSourceManager().getImmediateMacroCallerLoc(l);
     }
@@ -815,12 +803,6 @@ bool FakeBool::VisitFieldDecl(FieldDecl const * decl) {
     if (!handler.isAllRelevantCodeDefined(decl)) {
         return true;
     }
-    if (k == FBK_sal_Bool
-        && isInSpecialMainFile(
-            compiler.getSourceManager().getSpellingLoc(decl->getBeginLoc())))
-    {
-        return true;
-    }
     TagDecl const * td = dyn_cast<TagDecl>(decl->getDeclContext());
     if (td == nullptr) {
         //TODO: ObjCInterface
@@ -877,19 +859,6 @@ bool FakeBool::VisitValueDecl(ValueDecl const * decl) {
     return true;
 }
 
-bool FakeBool::TraverseStaticAssertDecl(StaticAssertDecl * decl) {
-    // Ignore special code like
-    //
-    //   static_cast<sal_Bool>(true) == sal_True
-    //
-    // inside static_assert in cppu/source/uno/check.cxx:
-    return
-        loplugin::isSamePathname(
-            getFilenameOfLocation(decl->getLocation()),
-            SRCDIR "/cppu/source/uno/check.cxx")
-        || RecursiveASTVisitor::TraverseStaticAssertDecl(decl);
-}
-
 bool FakeBool::TraverseLinkageSpecDecl(LinkageSpecDecl * decl) {
     assert(externCContexts_ != std::numeric_limits<unsigned int>::max()); 
//TODO
     ++externCContexts_;
@@ -917,16 +886,6 @@ bool FakeBool::isSharedCAndCppCode(SourceLocation 
location) const {
             || compiler.getSourceManager().isMacroBodyExpansion(location));
 }
 
-bool FakeBool::isInSpecialMainFile(SourceLocation spellingLocation) const {
-    if (!compiler.getSourceManager().isInMainFile(spellingLocation)) {
-        return false;
-    }
-    auto f = getFilenameOfLocation(spellingLocation);
-    return loplugin::isSamePathname(f, SRCDIR "/cppu/qa/test_any.cxx")
-        || loplugin::isSamePathname(f, SRCDIR "/cppu/source/uno/check.cxx");
-        // TODO: the offset checks
-}
-
 bool FakeBool::rewrite(SourceLocation location, FakeBoolKind kind) {
     if (rewriter != nullptr) {
         //TODO: "::sal_Bool" -> "bool", not "::bool"
diff --git a/cppu/qa/test_any.cxx b/cppu/qa/test_any.cxx
index 4cf9d181984f..757040314844 100644
--- a/cppu/qa/test_any.cxx
+++ b/cppu/qa/test_any.cxx
@@ -228,6 +228,7 @@ void Test::testVoid() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -336,6 +337,7 @@ void Test::testBoolean() {
         CPPUNIT_ASSERT_MESSAGE("bool", !b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", (a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !b);
@@ -446,6 +448,7 @@ void Test::testByte() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -556,6 +559,7 @@ void Test::testShort() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -668,6 +672,7 @@ void Test::testUnsignedShort() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -778,6 +783,7 @@ void Test::testLong() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -888,6 +894,7 @@ void Test::testUnsignedLong() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -998,6 +1005,7 @@ void Test::testHyper() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1108,6 +1116,7 @@ void Test::testUnsignedHyper() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1218,6 +1227,7 @@ void Test::testFloat() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1328,6 +1338,7 @@ void Test::testDouble() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1439,6 +1450,7 @@ void Test::testChar() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1549,6 +1561,7 @@ void Test::testString() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1659,6 +1672,7 @@ void Test::testType() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1770,6 +1784,7 @@ void Test::testSequence() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -1899,6 +1914,7 @@ void Test::testEnum() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -2014,6 +2030,7 @@ void Test::testStruct() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -2155,6 +2172,7 @@ void Test::testException() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -2290,6 +2308,7 @@ void Test::testInterface() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
@@ -2421,6 +2440,7 @@ void Test::testNull() {
         CPPUNIT_ASSERT_MESSAGE("bool", b);
     }
     {
+        // [-loplugin:fakebool] false positive:
         sal_Bool b = true;
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", !(a >>= b));
         CPPUNIT_ASSERT_MESSAGE("sal_Bool", b);
diff --git a/cppu/source/uno/check.cxx b/cppu/source/uno/check.cxx
index 8e99ff0a35c3..2c289587c8a6 100644
--- a/cppu/source/uno/check.cxx
+++ b/cppu/source/uno/check.cxx
@@ -69,8 +69,11 @@ struct D
 };
 struct E
 {
+    // [-loplugin:fakebool] false positive:
     sal_Bool a;
+    // [-loplugin:fakebool] false positive:
     sal_Bool b;
+    // [-loplugin:fakebool] false positive:
     sal_Bool c;
     sal_Int16 d;
     sal_Int32 e;
@@ -142,8 +145,10 @@ enum Enum
 #   pragma pack(pop)
 #endif
 
+// [-loplugin:fakebool] false positive:
 static_assert( static_cast<sal_Bool>(true) == sal_True,
                "must be binary compatible" );
+// [-loplugin:fakebool] false positive:
 static_assert( static_cast<sal_Bool>(false) == sal_False,
                "must be binary compatible" );
 #if SAL_TYPES_ALIGNMENT8 == 2

Reply via email to