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

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Tue Nov 26 06:13:24 UTC 2019


 compilerplugins/clang/implicitboolconversion.cxx      |   13 ++++++++
 compilerplugins/clang/test/implicitboolconversion.cxx |   28 ++++++++++++++++++
 solenv/CompilerTest_compilerplugins_clang.mk          |    1 
 3 files changed, 42 insertions(+)

New commits:
commit 28f8a26fa12c2f78696864189356db46c1cae30c
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Nov 25 11:17:19 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Nov 26 07:12:15 2019 +0100

    loplugin:implicitboolconversion: Filter out bool -> std::atomic<bool>
    
    ...as used since patch set 8 of <https://gerrit.libreoffice.org/#/c/81542/8>
    "WIP: tdf#120006 New Document converter"
    
    Change-Id: I79c2237a2e5839162272c0d49bdb4d87c9e35102
    Reviewed-on: https://gerrit.libreoffice.org/83655
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx
index e16b15517bc9..3adbf7197f47 100644
--- a/compilerplugins/clang/implicitboolconversion.cxx
+++ b/compilerplugins/clang/implicitboolconversion.cxx
@@ -1020,6 +1020,19 @@ void ImplicitBoolConversion::checkCXXConstructExpr(
 
 void ImplicitBoolConversion::reportWarning(ImplicitCastExpr const * expr) {
     if (compiler.getLangOpts().CPlusPlus) {
+        if (expr->getCastKind() == CK_ConstructorConversion) {
+            auto const t1 = expr->getType();
+            if (auto const t2 = t1->getAs<TemplateSpecializationType>()) {
+                assert(t2->getNumArgs() >= 1);
+                auto const a = t2->getArg(0);
+                if (a.getKind() == TemplateArgument::Type && a.getAsType()->isBooleanType()
+                    && (loplugin::TypeCheck(t1).TemplateSpecializationClass()
+                        .ClassOrStruct("atomic").StdNamespace()))
+                {
+                    return;
+                }
+            }
+        }
         report(
             DiagnosticsEngine::Warning,
             "implicit conversion (%0) from %1 to %2", compat::getBeginLoc(expr))
diff --git a/compilerplugins/clang/test/implicitboolconversion.cxx b/compilerplugins/clang/test/implicitboolconversion.cxx
new file mode 100644
index 000000000000..c438822d3b88
--- /dev/null
+++ b/compilerplugins/clang/test/implicitboolconversion.cxx
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <atomic>
+
+void f()
+{
+    // expected-error at +1 {{implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]}}
+    int i = false;
+    (void)i;
+    std::atomic<bool> b = false;
+    (void)b;
+    //TODO: Emit only one diagnostic here:
+    // expected-error at +2 {{implicit conversion (ConstructorConversion) from 'bool' to 'std::atomic<int>' [loplugin:implicitboolconversion]}}
+    // expected-error-re at +1 {{implicit conversion (IntegralCast) from 'bool' to {{.+}} [loplugin:implicitboolconversion]}}
+    std::atomic<int> a = false;
+    (void)a;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index 318bf8c69d0a..3c9969bd628f 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -41,6 +41,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
     compilerplugins/clang/test/flatten \
     compilerplugins/clang/test/fragiledestructor \
     compilerplugins/clang/test/getstr \
+    compilerplugins/clang/test/implicitboolconversion \
     compilerplugins/clang/test/indentation \
     compilerplugins/clang/test/intvsfloat \
     compilerplugins/clang/test/logexceptionnicely \


More information about the Libreoffice-commits mailing list