diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-11-25 11:17:19 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-11-26 07:12:15 +0100 |
commit | 28f8a26fa12c2f78696864189356db46c1cae30c (patch) | |
tree | ec47d8bc2ace02e6e64f8fec400e4bc2eadb4c5b | |
parent | e9a60f3d9ba7c6164851264e7171b90238f7948c (diff) |
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@redhat.com>
-rw-r--r-- | compilerplugins/clang/implicitboolconversion.cxx | 13 | ||||
-rw-r--r-- | compilerplugins/clang/test/implicitboolconversion.cxx | 28 | ||||
-rw-r--r-- | solenv/CompilerTest_compilerplugins_clang.mk | 1 |
3 files changed, 42 insertions, 0 deletions
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@+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@+2 {{implicit conversion (ConstructorConversion) from 'bool' to 'std::atomic<int>' [loplugin:implicitboolconversion]}} + // expected-error-re@+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 \ |