loplugin:redundantfcast improve to find redundant double casts

Change-Id: I0d0ff9035e5bb5bc3f3b4c903bf221ed8d34a141
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202154
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2026-03-22 20:19:39 +01:00
parent 59b9f0916d
commit 06cbb383c9
20 changed files with 54 additions and 45 deletions
@@ -152,8 +152,8 @@ void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
m_nZRotation = m_xMFZRotation->get_value(FieldUnit::DEGREE);
fXAngle = double(m_nXRotation)/pow(10.0,m_xMFXRotation->get_digits());
fYAngle = double(-1.0*m_nYRotation)/pow(10.0,m_xMFYRotation->get_digits());
fZAngle = double(-1.0*m_nZRotation)/pow(10.0,m_xMFZRotation->get_digits());
fYAngle = (-1.0*m_nYRotation)/pow(10.0,m_xMFYRotation->get_digits());
fZAngle = (-1.0*m_nZRotation)/pow(10.0,m_xMFZRotation->get_digits());
fXAngle = basegfx::deg2rad(fXAngle);
fYAngle = basegfx::deg2rad(fYAngle);
+2 -4
View File
@@ -310,15 +310,13 @@ public:
if (const auto* BT = dyn_cast<BuiltinType>(t1->getUnqualifiedDesugaredType()))
{
auto k = BT->getKind();
if (k == BuiltinType::Double || k == BuiltinType::Float
|| (k >= BuiltinType::Bool && k <= BuiltinType::Int128))
if (k >= BuiltinType::Bool && k <= BuiltinType::Int128)
return true;
}
if (const auto* BT = dyn_cast<BuiltinType>(t2->getUnqualifiedDesugaredType()))
{
auto k = BT->getKind();
if (k == BuiltinType::Double || k == BuiltinType::Float
|| (k >= BuiltinType::Bool && k <= BuiltinType::Int128))
if (k >= BuiltinType::Bool && k <= BuiltinType::Int128)
return true;
}
auto tc = loplugin::TypeCheck(t1);
@@ -236,4 +236,15 @@ void f()
}
}
namespace test10
{
void f(double x);
void g()
{
double oogah = 0;
// expected-error@+1 {{redundant functional cast from 'double' to 'double' [loplugin:redundantfcast]}}
f(double(oogah));
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
+1 -1
View File
@@ -545,7 +545,7 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, testWriterFontwork)
CPPUNIT_ASSERT_EQUAL(uno::Any(u"Courier New"_ustr),
xShapeProps->getPropertyValue(u"CharFontName"_ustr));
CPPUNIT_ASSERT_EQUAL(uno::Any(float(awt::FontWeight::BOLD)),
CPPUNIT_ASSERT_EQUAL(uno::Any(awt::FontWeight::BOLD),
xShapeProps->getPropertyValue(u"CharWeight"_ustr));
lang::Locale aCharLocale;
+1 -1
View File
@@ -574,7 +574,7 @@ void ViewSettings::finalizeImport()
aPropMap.setProperty( PROP_HasHorizontalScrollBar, rModel.mbShowHorScroll);
aPropMap.setProperty( PROP_HasVerticalScrollBar, rModel.mbShowVerScroll);
aPropMap.setProperty( PROP_HasSheetTabs, rModel.mbShowTabBar);
aPropMap.setProperty( PROP_RelativeHorizontalTabbarWidth, double( rModel.mnTabBarWidth / 1000.0 ));
aPropMap.setProperty( PROP_RelativeHorizontalTabbarWidth, rModel.mnTabBarWidth / 1000.0);
aPropMap.setProperty( PROP_ShowObjects, nShowMode);
aPropMap.setProperty( PROP_ShowCharts, nShowMode);
aPropMap.setProperty( PROP_ShowDrawing, nShowMode);
+2 -2
View File
@@ -247,8 +247,8 @@ private:
Color const& rColor)
{
auto& rMarker = rMarkers.emplace_back();
const double nHalfSizeX = double(mnOneX * 2 * mfScaleX);
const double nHalfSizeY = double(mnOneY * 2 * mfScaleY);
const double nHalfSizeX = mnOneX * 2 * mfScaleX;
const double nHalfSizeY = mnOneY * 2 * mfScaleY;
basegfx::B2DRectangle aRectangle(std::round(x - nHalfSizeX), std::round(y - nHalfSizeY),
std::round(x + nHalfSizeX), std::round(y + nHalfSizeY));
rMarker.maPolygon = basegfx::utils::createPolygonFromRect(aRectangle);
@@ -79,7 +79,7 @@ uno::Sequence<uno::Any> SAL_CALL PivotTableDataSequence::getData()
for (ValueAndFormat const & rItem : m_aData)
{
if (rItem.m_eType == ValueType::Numeric)
pSeq[i] <<= double(rItem.m_fValue);
pSeq[i] <<= rItem.m_fValue;
else if (rItem.m_eType == ValueType::String)
pSeq[i] <<= rItem.m_aString;
+1 -1
View File
@@ -2468,7 +2468,7 @@ void ScOutputData::DrawSparklines(vcl::RenderContext& rRenderContext)
Size aSize(nWidth, nHeight);
sc::SparklineRenderer renderer(*mpDoc);
renderer.render(pSparkline, rRenderContext, tools::Rectangle(aPoint, aSize), 1, 1, double(mfZoomX), double(mfZoomY));
renderer.render(pSparkline, rRenderContext, tools::Rectangle(aPoint, aSize), 1, 1, mfZoomX, mfZoomY);
}
nPosX += mpRowInfo[0].basicCellInfo(nX).nWidth * nLayoutSign;
+1 -1
View File
@@ -187,7 +187,7 @@ bool PathDragResize::EndSdrDrag(bool /*bCopy*/)
{
const Point aRef( DragStat().GetRef1() );
basegfx::B2DHomMatrix aTrans(basegfx::utils::createTranslateB2DHomMatrix(-aRef.X(), -aRef.Y()));
aTrans.scale(double(m_aXFact), double(m_aYFact));
aTrans.scale(m_aXFact, m_aYFact);
aTrans.translate(aRef.X(), aRef.Y());
basegfx::B2DPolyPolygon aDragPoly(pPathObj->GetPathPoly());
aDragPoly.transform(aTrans);
+15 -15
View File
@@ -1825,7 +1825,7 @@ basegfx::B2DHomMatrix SdrDragResize::getCurrentTransformation() const
{
basegfx::B2DHomMatrix aRetval(basegfx::utils::createTranslateB2DHomMatrix(
-DragStat().GetRef1().X(), -DragStat().GetRef1().Y()));
aRetval.scale(double(m_aXFact), double(m_aYFact));
aRetval.scale(m_aXFact, m_aYFact);
aRetval.translate(DragStat().GetRef1().X(), DragStat().GetRef1().Y());
return aRetval;
@@ -2271,12 +2271,12 @@ basegfx::B2DHomMatrix SdrDragShear::getCurrentTransformation() const
{
if (bVertical)
{
aRetval.scale(double(aFact), 1.0);
aRetval.scale(aFact, 1.0);
aRetval.shearY(-nTan);
}
else
{
aRetval.scale(1.0, double(aFact));
aRetval.scale(1.0, aFact);
aRetval.shearX(-nTan);
}
}
@@ -2403,11 +2403,11 @@ void SdrDragShear::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
{
if (bVertical)
{
rTarget.Resize(DragStat().GetRef1(),double(aFact),1);
rTarget.Resize(DragStat().GetRef1(),aFact,1);
}
else
{
rTarget.Resize(DragStat().GetRef1(),1,double(aFact));
rTarget.Resize(DragStat().GetRef1(),1,aFact);
}
}
@@ -2440,11 +2440,11 @@ bool SdrDragShear::EndSdrDrag(bool bCopy)
{
if (bVertical)
{
getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),double(aFact),1.0,bCopy);
getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),aFact,1.0,bCopy);
}
else
{
getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),1.0,double(aFact),bCopy);
getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),1.0,aFact,bCopy);
}
bCopy=false;
@@ -3270,11 +3270,11 @@ void SdrDragCrook::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
{
if (bVertical)
{
rTarget.Resize(aCenter,aFact1,double(aFact));
rTarget.Resize(aCenter,aFact1,aFact);
}
else
{
rTarget.Resize(aCenter,double(aFact),aFact1);
rTarget.Resize(aCenter,aFact,aFact1);
}
}
else
@@ -3284,11 +3284,11 @@ void SdrDragCrook::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
if (bVertical)
{
ResizePoint(aCtr1,aCenter,aFact1,double(aFact));
ResizePoint(aCtr1,aCenter,aFact1,aFact);
}
else
{
ResizePoint(aCtr1,aCenter,double(aFact),aFact1);
ResizePoint(aCtr1,aCenter,aFact,aFact1);
}
Size aSiz(aCtr1.X()-aCtr0.X(),aCtr1.Y()-aCtr0.Y());
@@ -3342,9 +3342,9 @@ bool SdrDragCrook::EndSdrDrag(bool bCopy)
if (bContortion)
{
if (bVertical)
getSdrDragView().ResizeMarkedObj(aCenter,aFact1,double(aFact),bCopy);
getSdrDragView().ResizeMarkedObj(aCenter,aFact1,aFact,bCopy);
else
getSdrDragView().ResizeMarkedObj(aCenter,double(aFact),aFact1,bCopy);
getSdrDragView().ResizeMarkedObj(aCenter,aFact,aFact1,bCopy);
}
else
{
@@ -3362,9 +3362,9 @@ bool SdrDragCrook::EndSdrDrag(bool bCopy)
Point aCtr1(aCtr0);
if (bVertical)
ResizePoint(aCtr1,aCenter,aFact1,double(aFact));
ResizePoint(aCtr1,aCenter,aFact1,aFact);
else
ResizePoint(aCtr1,aCenter,double(aFact),aFact1);
ResizePoint(aCtr1,aCenter,aFact,aFact1);
Size aSiz(aCtr1.X()-aCtr0.X(),aCtr1.Y()-aCtr0.Y());
if( bUndo )
+1 -1
View File
@@ -265,7 +265,7 @@ void SdrEditView::ResizeMarkedObj(const Point& rRef, double xFact, double yFact,
AddUndoActions( CreateConnectorUndo( *pO ) );
AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pO));
}
pO->Resize(rRef,double(xFact),double(yFact));
pO->Resize(rRef,xFact,yFact);
}
if( bUndo )
+1 -1
View File
@@ -2286,7 +2286,7 @@ void SdrPathObj::NbcResize(const Point& rRef, double xFact, double yFact)
basegfx::B2DHomMatrix aTrans(basegfx::utils::createTranslateB2DHomMatrix(-rRef.X(), -rRef.Y()));
aTrans = basegfx::utils::createScaleTranslateB2DHomMatrix(
double(xFact), double(yFact), rRef.X(), rRef.Y()) * aTrans;
xFact, yFact, rRef.X(), rRef.Y()) * aTrans;
maPathPolygon.transform(aTrans);
// #i19871# first modify locally, then call parent (to get correct SnapRect with GluePoints)
+1 -1
View File
@@ -399,7 +399,7 @@ SdrSnap SdrSnapView::SnapPos(Point& rPnt, const SdrPageView* pPV) const
x = static_cast<tools::Long>(static_cast<double>(x) * fSnapWidth + static_cast<double>(aGridOrigin.X()));
dx = 0;
}
fSnapWidth = double(maSnapWdtY);
fSnapWidth = maSnapWdtY;
if(dy == NOT_SNAPPED && fSnapWidth)
{
double fy = static_cast<double>(y);
+2 -2
View File
@@ -269,8 +269,8 @@ bool SdrExchangeView::Paste(
if (bResize)
{
FrPair aResize(GetMapFactor(eSrcUnit,eDstUnit));
aXResize=double(aResize.X());
aYResize=double(aResize.Y());
aXResize=aResize.X();
aYResize=aResize.Y();
}
SdrObjList* pDstLst=pLst;
sal_uInt16 nPg,nPgCount=pSrcMod->GetPageCount();
+1 -1
View File
@@ -2118,7 +2118,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testXFlatParagraph)
CPPUNIT_ASSERT_EQUAL(xFlatPara2->getText(), xFlatPara4->getText());
//changing the attributes of last para
uno::Sequence<beans::PropertyValue> aDescriptor( comphelper::InitPropertySequence({
{ "CharWeight", uno::Any(float(css::awt::FontWeight::BOLD)) }
{ "CharWeight", uno::Any(css::awt::FontWeight::BOLD) }
}));
xFlatPara3->changeAttributes(sal_Int32(0), sal_Int32(5), aDescriptor);
//checking Language Portions
+6 -6
View File
@@ -236,7 +236,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf99672SearchReplaceEmptyStringUsingF
// Search for text with bold formatting
uno::Reference<util::XPropertyReplace> xProp(xReplaceDes, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aSearchAttr(comphelper::InitPropertySequence(
{ { "CharWeight", uno::Any(float(css::awt::FontWeight::BOLD)) } }));
{ { "CharWeight", uno::Any(css::awt::FontWeight::BOLD) } }));
xProp->setSearchAttributes(aSearchAttr);
xReplaceDes->setSearchString(u"abc"_ustr);
@@ -296,13 +296,13 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTextSearch)
uno::Reference<util::XPropertyReplace> xProp(xSearchDes, uno::UNO_QUERY);
//setting some properties
uno::Sequence<beans::PropertyValue> aDescriptor(comphelper::InitPropertySequence(
{ { "CharWeight", uno::Any(float(css::awt::FontWeight::BOLD)) } }));
{ { "CharWeight", uno::Any(css::awt::FontWeight::BOLD) } }));
xProp->setSearchAttributes(aDescriptor);
//receiving the defined properties and asserting them with expected values, covering UNO
uno::Sequence<beans::PropertyValue> aPropVal2(xProp->getSearchAttributes());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aPropVal2.getLength());
CPPUNIT_ASSERT_EQUAL(u"CharWeight"_ustr, aPropVal2[0].Name);
CPPUNIT_ASSERT_EQUAL(uno::Any(float(css::awt::FontWeight::BOLD)), aPropVal2[0].Value);
CPPUNIT_ASSERT_EQUAL(uno::Any(css::awt::FontWeight::BOLD), aPropVal2[0].Value);
//specifying the search attributes
uno::Reference<beans::XPropertySet> xPropSet(xSearchDes, uno::UNO_QUERY_THROW);
xPropSet->setPropertyValue(u"SearchWords"_ustr, uno::Any(true));
@@ -319,7 +319,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTextSearch)
uno::Sequence<beans::PropertyValue> aRepProp(xProp2->getReplaceAttributes());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRepProp.getLength());
CPPUNIT_ASSERT_EQUAL(u"CharWeight"_ustr, aRepProp[0].Name);
CPPUNIT_ASSERT_EQUAL(uno::Any(float(css::awt::FontWeight::BOLD)), aRepProp[0].Value);
CPPUNIT_ASSERT_EQUAL(uno::Any(css::awt::FontWeight::BOLD), aRepProp[0].Value);
//setting strings for replacement
xReplaceDes->setSearchString(u"test"_ustr);
xReplaceDes->setReplaceString(u"task"_ustr);
@@ -1838,8 +1838,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testPropertyDefaults)
//testing CharWeight from style::CharacterProperties
uno::Any aCharWeight = xPropSet->getPropertyValue(u"CharWeight"_ustr);
//changing the default value
xPropSet->setPropertyValue(u"CharWeight"_ustr, uno::Any(float(awt::FontWeight::BOLD)));
CPPUNIT_ASSERT_EQUAL(uno::Any(float(awt::FontWeight::BOLD)),
xPropSet->setPropertyValue(u"CharWeight"_ustr, uno::Any(awt::FontWeight::BOLD));
CPPUNIT_ASSERT_EQUAL(uno::Any(awt::FontWeight::BOLD),
xPropSet->getPropertyValue(u"CharWeight"_ustr));
//resetting the value to default
xPropState->setPropertyToDefault(u"CharWeight"_ustr);
+1 -1
View File
@@ -1019,7 +1019,7 @@ void SwVirtFlyDrawObj::NbcResize(const Point& rRef, double xFact, double yFact)
// apply state to already valid transformation
aNewMat.translate(-aRef.getX(), -aRef.getY());
aNewMat.scale(double(xFact), double(yFact));
aNewMat.scale(xFact, yFact);
aNewMat.translate(aRef.getX(), aRef.getY());
// get center of transformed state
+1 -1
View File
@@ -497,7 +497,7 @@ private:
float atspiPosition;
int nConsumed;
CPPUNIT_ASSERT_EQUAL(1, sscanf(p, "%gmm%n", &atspiPosition, &nConsumed));
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(rTabStop.Position * 0.01f), atspiPosition, 1e-4);
CPPUNIT_ASSERT_DOUBLES_EQUAL(rTabStop.Position * 0.01f, atspiPosition, 1e-4);
p += nConsumed;
if (*p)
+1 -1
View File
@@ -260,7 +260,7 @@ double LogicalFontInstance::GetGlyphWidth(sal_GlyphId nGlyph, bool bVertical, bo
double nScale = 0;
GetScale(&nScale, nullptr);
return double(nWidth * nScale);
return nWidth * nScale;
}
bool LogicalFontInstance::IsGraphiteFont()
+2 -2
View File
@@ -319,8 +319,8 @@ void ColorFieldControl::ShowPosition( const Point& rPos, bool bUpdate )
if (bUpdate)
{
mdX = double(nX) / double(aSize.Width() - 1.0);
mdY = double(aSize.Height() - 1.0 - nY) / double(aSize.Height() - 1.0);
mdX = double(nX) / (aSize.Width() - 1.0);
mdY = (aSize.Height() - 1.0 - nY) / (aSize.Height() - 1.0);
}
}