summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compilerplugins/clang/implicitboolconversion.cxx13
-rw-r--r--cppu/source/uno/assign.hxx2
-rw-r--r--cppu/source/uno/copy.hxx4
-rw-r--r--cppu/source/uno/eq.hxx8
-rw-r--r--include/com/sun/star/uno/Any.hxx10
-rw-r--r--xmlscript/source/xmldlg_imexp/xmldlg_export.cxx8
6 files changed, 28 insertions, 17 deletions
diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx
index 8aa65434a8c5..9fa073c43fd7 100644
--- a/compilerplugins/clang/implicitboolconversion.cxx
+++ b/compilerplugins/clang/implicitboolconversion.cxx
@@ -110,6 +110,11 @@ bool isMatchingBool(Expr const * expr, Expr const * comparisonExpr) {
|| areSameTypedef(expr->getType(), comparisonExpr->getType());
}
+bool isSalBool(QualType type) {
+ auto t = type->getAs<TypedefType>();
+ return t != nullptr && t->getDecl()->getName() == "sal_Bool";
+}
+
bool isBoolExpr(Expr const * expr) {
if (isBool(expr)) {
return true;
@@ -836,6 +841,14 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr(
== expr->getType().IgnoreParens())
&& isBool(sub->getSubExpr()->IgnoreParenImpCasts()))
{
+ // Ignore "normalizing cast" bool(b) from sal_Bool b to bool, then
+ // implicitly cast back again to sal_Bool:
+ if (dyn_cast<CXXFunctionalCastExpr>(sub) != nullptr
+ && sub->getType()->isBooleanType() && isSalBool(expr->getType())
+ && isSalBool(sub->getSubExpr()->IgnoreParenImpCasts()->getType()))
+ {
+ return true;
+ }
report(
DiagnosticsEngine::Warning,
"explicit conversion (%0) from %1 to %2 implicitly cast back to %3",
diff --git a/cppu/source/uno/assign.hxx b/cppu/source/uno/assign.hxx
index 5c6dc3202c9b..59257c44b09a 100644
--- a/cppu/source/uno/assign.hxx
+++ b/cppu/source/uno/assign.hxx
@@ -138,7 +138,7 @@ inline bool _assignData(
switch (pSourceType->eTypeClass)
{
case typelib_TypeClass_BOOLEAN:
- *static_cast<sal_Bool *>(pDest) = (*static_cast<sal_Bool *>(pSource) != sal_False);
+ *static_cast<sal_Bool *>(pDest) = bool(*static_cast<sal_Bool *>(pSource));
return true;
default:
return false;
diff --git a/cppu/source/uno/copy.hxx b/cppu/source/uno/copy.hxx
index f1ec222e4e2d..1e132c06ac87 100644
--- a/cppu/source/uno/copy.hxx
+++ b/cppu/source/uno/copy.hxx
@@ -116,7 +116,7 @@ inline void _copyConstructAnyFromData(
break;
case typelib_TypeClass_BOOLEAN:
pDestAny->pData = &pDestAny->pReserved;
- *static_cast<sal_Bool *>(pDestAny->pData) = (*static_cast<sal_Bool *>(pSource) != sal_False);
+ *static_cast<sal_Bool *>(pDestAny->pData) = bool(*static_cast<sal_Bool *>(pSource));
break;
case typelib_TypeClass_BYTE:
pDestAny->pData = &pDestAny->pReserved;
@@ -524,7 +524,7 @@ inline void _copyConstructData(
*static_cast<sal_Unicode *>(pDest) = *static_cast<sal_Unicode *>(pSource);
break;
case typelib_TypeClass_BOOLEAN:
- *static_cast<sal_Bool *>(pDest) = (*static_cast<sal_Bool *>(pSource) != sal_False);
+ *static_cast<sal_Bool *>(pDest) = bool(*static_cast<sal_Bool *>(pSource));
break;
case typelib_TypeClass_BYTE:
*static_cast<sal_Int8 *>(pDest) = *static_cast<sal_Int8 *>(pSource);
diff --git a/cppu/source/uno/eq.hxx b/cppu/source/uno/eq.hxx
index 5a18e43dac19..008a204a104e 100644
--- a/cppu/source/uno/eq.hxx
+++ b/cppu/source/uno/eq.hxx
@@ -125,8 +125,8 @@ inline bool _equalSequence(
{
for ( sal_Int32 nPos = nElements; nPos--; )
{
- if ((static_cast<sal_Bool *>(pDestElements)[nPos] != sal_False) !=
- (static_cast<sal_Bool *>(pSourceElements)[nPos] != sal_False))
+ if (bool(static_cast<sal_Bool *>(pDestElements)[nPos]) !=
+ bool(static_cast<sal_Bool *>(pSourceElements)[nPos]))
{
return false;
}
@@ -286,8 +286,8 @@ inline bool _equalData(
&& *static_cast<sal_Unicode *>(pDest) == *static_cast<sal_Unicode *>(pSource);
case typelib_TypeClass_BOOLEAN:
return eSourceTypeClass == typelib_TypeClass_BOOLEAN
- && ((*static_cast<sal_Bool *>(pDest) != sal_False)
- == (*static_cast<sal_Bool *>(pSource) != sal_False));
+ && (bool(*static_cast<sal_Bool *>(pDest))
+ == bool(*static_cast<sal_Bool *>(pSource)));
case typelib_TypeClass_BYTE:
switch (eSourceTypeClass)
{
diff --git a/include/com/sun/star/uno/Any.hxx b/include/com/sun/star/uno/Any.hxx
index 79f0cdbbe4f2..cbd8fb6e287e 100644
--- a/include/com/sun/star/uno/Any.hxx
+++ b/include/com/sun/star/uno/Any.hxx
@@ -260,7 +260,7 @@ inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal
{
if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass)
{
- value = (* static_cast< const sal_Bool * >( rAny.pData ) != sal_False);
+ value = bool(* static_cast< const sal_Bool * >( rAny.pData ));
return true;
}
return false;
@@ -270,7 +270,7 @@ template<>
inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value )
{
return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass &&
- (value != sal_False) == (* static_cast< const sal_Bool * >( rAny.pData ) != sal_False));
+ bool(value) == bool(* static_cast< const sal_Bool * >( rAny.pData )));
}
@@ -279,8 +279,7 @@ inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
{
if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN)
{
- value = *static_cast< sal_Bool const * >(
- rAny.pData ) != sal_False;
+ value = *static_cast< sal_Bool const * >( rAny.pData );
return true;
}
return false;
@@ -292,8 +291,7 @@ inline bool SAL_CALL operator == ( Any const & rAny, bool const & value )
{
return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN &&
(value ==
- (*static_cast< sal_Bool const * >( rAny.pData )
- != sal_False)));
+ bool(*static_cast< sal_Bool const * >( rAny.pData ))));
}
// byte
diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx
index 35264f3cc38b..d4a250984e54 100644
--- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx
+++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx
@@ -381,12 +381,12 @@ Reference< xml::sax::XAttributeList > Style::createElement()
pStyle->addAttribute( XMLNS_DIALOGS_PREFIX ":font-orientation", OUString::number( (float)_descr.Orientation ) );
}
// dialog:font-kerning %boolean; #IMPLIED
- if ((def_descr.Kerning != sal_False) != (_descr.Kerning != sal_False))
+ if (bool(def_descr.Kerning) != bool(_descr.Kerning))
{
pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-kerning", _descr.Kerning );
}
// dialog:font-wordlinemode %boolean; #IMPLIED
- if ((def_descr.WordLineMode != sal_False) != (_descr.WordLineMode != sal_False))
+ if (bool(def_descr.WordLineMode) != bool(_descr.WordLineMode))
{
pStyle->addBoolAttr( XMLNS_DIALOGS_PREFIX ":font-wordlinemode", _descr.WordLineMode );
}
@@ -1254,8 +1254,8 @@ inline bool equalFont( Style const & style1, Style const & style2 )
f1.Underline == f2.Underline &&
f1.Strikeout == f2.Strikeout &&
f1.Orientation == f2.Orientation &&
- (f1.Kerning != sal_False) == (f2.Kerning != sal_False) &&
- (f1.WordLineMode != sal_False) == (f2.WordLineMode != sal_False) &&
+ bool(f1.Kerning) == bool(f2.Kerning) &&
+ bool(f1.WordLineMode) == bool(f2.WordLineMode) &&
f1.Type == f2.Type &&
style1._fontRelief == style2._fontRelief &&
style1._fontEmphasisMark == style2._fontEmphasisMark