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>
This commit is contained in:
Stephan Bergmann 2019-11-25 11:17:19 +01:00
parent e9a60f3d9b
commit 28f8a26fa1
3 changed files with 42 additions and 0 deletions

View File

@ -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))

View File

@ -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: */

View File

@ -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 \