Files
odfstudio/compilerplugins/clang/test/implicitboolconversion.cxx
T
Stephan Bergmann e53d782042 Adapt loplugins to glibc 2.44 assert macro internals
...which started to cause issues like

> [CXX] sal/osl/all/acceptableaccessdenial.cxx
> engine/sal/osl/all/acceptableaccessdenial.cxx:30:5: error: implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]
>    30 |     assert(acceptableAccessDenials > 0);
>       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /usr/include/assert.h:139:23: note: expanded from macro 'assert'
>   139 |       ? void (1 ? 1 : bool (__VA_ARGS__))                               \
>       |                       ^~~~~~~~~~~~~~~~~~
> engine/sal/osl/all/acceptableaccessdenial.cxx:30:5: error: redundant functional cast from 'bool' to 'bool' [loplugin:redundantcast]
>    30 |     assert(acceptableAccessDenials > 0);
>       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /usr/include/assert.h:139:23: note: expanded from macro 'assert'
>   139 |       ? void (1 ? 1 : bool (__VA_ARGS__))                               \
>       |                       ^~~~~~~~~~~~~~~~~~

and

> [C  ] soltools/cpp/_tokens.c
> engine/soltools/cpp/_tokens.c:56:17: error: possibly unwanted implicit conversion when calling bool param [loplugin:pointerbool]
>    56 |     assert(trp->bp); // realloc failure is OOM -> no point to handle
>       |            ~~~~~^~
> /usr/include/assert.h:164:42: note: expanded from macro 'assert'
>   164 |     ((void) sizeof (__assert_single_arg (__VA_ARGS__)), __extension__ ({ \
>       |                                          ^~~~~~~~~~~
> /usr/include/assert.h:114:40: note: method here [loplugin:pointerbool]
>   114 | extern _Bool __assert_single_arg (_Bool);
>       |                                   ~~~~~^
> engine/soltools/cpp/_tokens.c:56:12: error: implicit conversion (PointerToBoolean) of call argument from 'Token *' (aka 'struct token *') to 'bool' [loplugin:implicitboolconversion]
>    56 |     assert(trp->bp); // realloc failure is OOM -> no point to handle
>       |            ^~~~~~~
> /usr/include/assert.h:164:42: note: expanded from macro 'assert'
>   164 |     ((void) sizeof (__assert_single_arg (__VA_ARGS__)), __extension__ ({ \
>       |                                          ^~~~~~~~~~~

and

> [CPT] compilerplugins/clang/test/consttobool.cxx
> error: 'expected-error' diagnostics seen but not expected:
>   Line 72: implicit conversion of constant &"msg"[0] of type 'const char *' to 'bool'; use 'true' instead [loplugin:consttobool]
> 1 error generated.

against glibc-devel-2.44-1.fc45.x86_64

[Cherry-pick note by Michael Weghorn:
clang-format was run on the files modified by this commit
to adhere to code style as mandated by the LibreOffice clang-format rules,
while the Collabora repository that this commit was cherry-picked
from doesn't check clang-format rules any more.
Based on the discussion in
https://gerrit.libreoffice.org/c/core/+/211063/comments/d368cf20_d66d1a50 ,
I'm adding myself as co-author to clarify the cherry-picked commit
contains those additional changes to the original commit by Stephan
from the Collabora main branch.]

Signed-off-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Change-Id: I53d66f280ea82d295a2c2c086f4d02a965a893d7
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/12738
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit ecce89b1fe7f0b1f09c13c46625b33443b1dadfb)
Co-authored-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211063
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2026-09-21 11:49:48 +02:00

94 lines
2.6 KiB
C++

/* -*- 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 <array>
#include <atomic>
#include <cassert>
#include <initializer_list>
#include <com/sun/star/uno/Sequence.hxx>
#include <sal/types.h>
template <typename T> struct Sequence
{
Sequence(std::initializer_list<T>);
};
template <typename T> struct Wrap1
{
T element;
};
template <typename T> struct Wrap2
{
Wrap2(T const& e)
: element(e)
{
}
T element;
};
bool g();
void h(bool);
void f()
{
// expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]}}
int i = false;
// expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]}}
i = true;
(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;
bool b2 = true;
b2 &= g();
(void)b2;
Sequence<sal_Bool> s1{ false };
(void)s1;
Sequence<Sequence<sal_Bool>> s2{ { false } };
(void)s2;
// expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'const int' [loplugin:implicitboolconversion]}}
Sequence<int> s3{ false };
(void)s3;
// expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'const int' [loplugin:implicitboolconversion]}}
Sequence<Sequence<int>> s4{ { false } };
(void)s4;
Wrap1<sal_Bool> w1{ false };
Sequence<Wrap1<sal_Bool>> s5{ { false } };
(void)s5;
Wrap2<sal_Bool> w2{ false };
(void)w2;
Sequence<Wrap2<sal_Bool>> s6{ { false } };
(void)s6;
h(w1.element);
css::uno::Sequence<sal_Bool> s7(1);
h(s7[0]);
std::array<sal_Bool, 1> s8;
s8[0] = false;
}
void testAssert([[maybe_unused]] bool b, [[maybe_unused]] int n)
{
assert(b);
#if !defined NDEBUG
// expected-error@+1 {{implicit conversion (IntegralCast) from 'bool' to 'int' [loplugin:implicitboolconversion]}}
assert(n = b);
#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */