Kaydet (Commit) b15f79a8 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:unnecessaryparen: signed numeric literals

Change-Id: I75c8224452ca9c3711a2ccaca9ecf549fa59cb64
Reviewed-on: https://gerrit.libreoffice.org/45549Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 32efde5c
......@@ -423,7 +423,7 @@ OUString lcl_getGridCIDForCommand( const OString& rDispatchCommand, const uno::R
uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, true/*bMainAxis*/, xDiagram ) );
sal_Int32 nSubGridIndex= bMainGrid ? (-1) : 0;
sal_Int32 nSubGridIndex= bMainGrid ? -1 : 0;
OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) );
return aCID;
}
......
......@@ -82,6 +82,15 @@ int main()
// Expecting just one error, not reported twice during TraverseInitListExpr:
int a[] = {(x)}; // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
(void) a;
(void) (+1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
(void) (-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
// For simplicity's sake, even warn about pathological cases that would require adding
// whitespace when removing the parentheses (as is also necessary in other cases anyway, like
// "throw(x);"); it is unlikely that there are any actual occurrences of code like "-(-1)" that
// would benefit from the parentheses readability-wise, compared to "- -1":
(void) -(-1); // expected-error {{unnecessary parentheses around signed numeric literal [loplugin:unnecessaryparen]}}
};
struct S2 {
......
......@@ -180,6 +180,19 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr)
<< parenExpr->getSourceRange();
handled_.insert(parenExpr);
}
} else if (auto const e = dyn_cast<UnaryOperator>(subExpr)) {
auto const op = e->getOpcode();
if (op == UO_Plus || op == UO_Minus) {
auto const e2 = e->getSubExpr();
if (isa<IntegerLiteral>(e2) || isa<FloatingLiteral>(e2) || isa<ImaginaryLiteral>(e2)) {
report(
DiagnosticsEngine::Warning,
"unnecessary parentheses around signed numeric literal",
parenExpr->getLocStart())
<< parenExpr->getSourceRange();
handled_.insert(parenExpr);
}
}
} else if (isa<CXXNamedCastExpr>(subExpr)) {
report(
DiagnosticsEngine::Warning, "unnecessary parentheses around cast",
......
......@@ -164,7 +164,7 @@ jint read_from_storage_stream( JNIEnv * env, jstring name, jstring key )
}
if (nBytesRead <= 0)
{
return (-1);
return -1;
}
else
{
......
......@@ -430,7 +430,7 @@ public:
sal_Unicode GetExtraValue() const { return nExtraValue; }
void SetExtraValue( sal_Unicode n ) { nExtraValue = n; }
bool HasValidSize() const { return aOutSz.Width() != (-1); }
bool HasValidSize() const { return aOutSz.Width() != -1; }
ExtraPortionInfo* GetExtraInfos() const { return xExtraInfos.get(); }
void SetExtraInfos( ExtraPortionInfo* p ) { xExtraInfos.reset(p); }
......
......@@ -1454,7 +1454,7 @@ EditPaM ImpEditEngine::WordLeft( const EditPaM& rPaM )
if ( aBoundary.startPos >= nCurrentPos )
aBoundary = _xBI->previousWord(
aNewPaM.GetNode()->GetString(), nCurrentPos, aLocale, css::i18n::WordType::ANYWORD_IGNOREWHITESPACES);
aNewPaM.SetIndex( ( aBoundary.startPos != (-1) ) ? aBoundary.startPos : 0 );
aNewPaM.SetIndex( ( aBoundary.startPos != -1 ) ? aBoundary.startPos : 0 );
}
return aNewPaM;
......@@ -1674,7 +1674,7 @@ void ImpEditEngine::InitScriptTypes( sal_Int32 nPara )
short nScriptType = _xBI->getScriptType( aText, nPos );
rTypes.emplace_back( nScriptType, nPos, nTextLen );
nPos = _xBI->endOfScript( aText, nPos, nScriptType );
while ( ( nPos != (-1) ) && ( nPos < nTextLen ) )
while ( ( nPos != -1 ) && ( nPos < nTextLen ) )
{
rTypes.back().nEndPos = nPos;
......
......@@ -934,7 +934,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
nTmpWidth -= rPrev.GetSize().Width();
nTmpPos = nTmpPos - rPrev.GetLen();
rPrev.SetLen(rPrev.GetLen() + nTmpLen);
rPrev.GetSize().Width() = (-1);
rPrev.GetSize().Width() = -1;
}
DBG_ASSERT( nTmpPortion < pParaPortion->GetTextPortions().Count(), "No more Portions left!" );
......@@ -2384,7 +2384,7 @@ sal_Int32 ImpEditEngine::SplitTextPortion( ParaPortion* pPortion, sal_Int32 nPos
}
}
else
pTextPortion->GetSize().Width() = (-1);
pTextPortion->GetSize().Width() = -1;
return nSplitPortion;
}
......@@ -2523,7 +2523,7 @@ void ImpEditEngine::RecalcTextPortion( ParaPortion* pParaPortion, sal_Int32 nSta
FindPortion( nStartPos, nPortionStart );
TextPortion& rTP = pParaPortion->GetTextPortions()[ nTP ];
rTP.SetLen( rTP.GetLen() + nNewChars );
rTP.GetSize().Width() = (-1);
rTP.GetSize().Width() = -1;
}
}
else
......@@ -2589,7 +2589,7 @@ void ImpEditEngine::RecalcTextPortion( ParaPortion* pParaPortion, sal_Int32 nSta
TextPortion& rPrev = pParaPortion->GetTextPortions()[nLastPortion - 1];
DBG_ASSERT( rPrev.GetKind() == PortionKind::TEXT, "Portion?!" );
rPrev.SetLen( rPrev.GetLen() + pTP->GetLen() );
rPrev.GetSize().Width() = (-1);
rPrev.GetSize().Width() = -1;
}
pParaPortion->GetTextPortions().Remove( nLastPortion );
}
......
......@@ -152,13 +152,13 @@ bool OutlinerView::PostKeyEvent( const KeyEvent& rKEvt, vcl::Window const * pFra
( pOwner->ImplGetOutlinerMode() != OutlinerMode::TitleObject ) &&
( bSelection || !aSel.nStartPos ) )
{
Indent( aKeyCode.IsShift() ? (-1) : (+1) );
Indent( aKeyCode.IsShift() ? -1 : +1 );
bKeyProcessed = true;
}
else if ( ( pOwner->ImplGetOutlinerMode() == OutlinerMode::TextObject ) &&
!bSelection && !aSel.nEndPos && pOwner->ImplHasNumberFormat( aSel.nEndPara ) )
{
Indent( aKeyCode.IsShift() ? (-1) : (+1) );
Indent( aKeyCode.IsShift() ? -1 : +1 );
bKeyProcessed = true;
}
}
......
......@@ -217,7 +217,7 @@ namespace XSLT
{
// const char *ptr = (const char *) context;
if (buffer == nullptr || len < 0)
return (-1);
return -1;
sal_Int32 n;
css::uno::Reference<XInputStream> xis = m_transformer->getInputStream();
n = xis.get()->readBytes(m_readBuf, len);
......
......@@ -1249,7 +1249,7 @@ css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchAlreadyLoaded()
// Note: To detect if a document was already loaded before
// we check URLs here only. But might the existing and the required
// document has different versions! Then its URLs are the same ...
sal_Int16 nNewVersion = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_VERSION(), (sal_Int16)(-1));
sal_Int16 nNewVersion = m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_VERSION(), (sal_Int16)-1);
// will be used to save the first hidden frame referring the searched model
// Normally we are interested on visible frames ... but if there is no such visible
......@@ -1298,7 +1298,7 @@ css::uno::Reference< css::frame::XFrame > LoadEnv::impl_searchAlreadyLoaded()
// or must not have any file revision set (-1 == -1!)
utl::MediaDescriptor lOldDocDescriptor(xModel->getArgs());
if (lOldDocDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_VERSION(), (sal_Int32)(-1)) != nNewVersion)
if (lOldDocDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_VERSION(), (sal_Int32)-1) != nNewVersion)
{
xTask.clear ();
continue;
......
......@@ -310,7 +310,7 @@ oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize)
/* Save current position */
off_t const nCurPos = lseek(m_fd, (off_t)0, SEEK_CUR);
if (nCurPos == (off_t)(-1))
if (nCurPos == (off_t)-1)
return result;
/* Try 'expand' via 'lseek()' and 'write()' */
......
......@@ -1778,12 +1778,12 @@ static bool lcl_parseDateTime(
if (bSuccess)
{
sal_Int16 const nTimezoneOffset = (bHaveTimezoneMinus ? (-1) : (+1))
sal_Int16 const nTimezoneOffset = (bHaveTimezoneMinus ? -1 : +1)
* ((nTimezoneHours * 60) + nTimezoneMinutes);
if (!pDate || bHaveTime) // time is optional
{
rDateTime.Year =
(isNegative ? (-1) : (+1)) * static_cast<sal_Int16>(nYear);
(isNegative ? -1 : +1) * static_cast<sal_Int16>(nYear);
rDateTime.Month = static_cast<sal_uInt16>(nMonth);
rDateTime.Day = static_cast<sal_uInt16>(nDay);
rDateTime.Hours = static_cast<sal_uInt16>(nHours);
......@@ -1818,7 +1818,7 @@ static bool lcl_parseDateTime(
else
{
pDate->Year =
(isNegative ? (-1) : (+1)) * static_cast<sal_Int16>(nYear);
(isNegative ? -1 : +1) * static_cast<sal_Int16>(nYear);
pDate->Month = static_cast<sal_uInt16>(nMonth);
pDate->Day = static_cast<sal_uInt16>(nDay);
if (bHaveTimezone)
......
......@@ -261,7 +261,7 @@ double Besselk1( double fNum )
fRet = log( fNum2 ) * BesselI( fNum, 1 ) +
( 1.0 + y * ( 0.15443144 + y * ( -0.67278579 + y * ( -0.18156897 + y * ( -0.1919402e-1 +
y * ( -0.110404e-2 + y * ( -0.4686e-4 ) ) ) ) ) ) )
y * ( -0.110404e-2 + y * -0.4686e-4 ) ) ) ) ) )
/ fNum;
}
else
......@@ -270,7 +270,7 @@ double Besselk1( double fNum )
fRet = exp( -fNum ) / sqrt( fNum ) * ( 1.25331414 + y * ( 0.23498619 +
y * ( -0.3655620e-1 + y * ( 0.1504268e-1 + y * ( -0.780353e-2 +
y * ( 0.325614e-2 + y * ( -0.68245e-3 ) ) ) ) ) ) );
y * ( 0.325614e-2 + y * -0.68245e-3 ) ) ) ) ) );
}
return fRet;
......
......@@ -285,7 +285,7 @@ void TextObjectBar::Execute( SfxRequest &rReq )
SvxLRSpaceItem aNewMargin( EE_PARA_LRSPACE );
aNewMargin.SetTextLeft( aParaMargin.GetTextLeft() + aParaMargin.GetTextFirstLineOfst() );
aNewMargin.SetRight( aParaMargin.GetRight() );
aNewMargin.SetTextFirstLineOfst( ( aParaMargin.GetTextFirstLineOfst() ) * (-1) );
aNewMargin.SetTextFirstLineOfst( ( aParaMargin.GetTextFirstLineOfst() ) * -1 );
aLRSpaceSet.Put( aNewMargin );
mpView->SetAttributes( aLRSpaceSet );
......
......@@ -338,7 +338,7 @@ IMPL_LINK( SvImpLBox, ScrollUpDownHdl, ScrollBar *, pScrollBar, void )
}
else
{
nDelta *= (-1);
nDelta *= -1;
if( nDelta == 1 )
CursorUp();
else
......
......@@ -276,7 +276,7 @@ void ParaPropertyPanel::StateChangedIndentImpl( SfxItemState eState, const SfxPo
&& maContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Default)
&& maContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Table))
{
mpFLineIndent->SetMin( nVal*(-1), FUNIT_100TH_MM );
mpFLineIndent->SetMin( nVal*-1, FUNIT_100TH_MM );
}
long nrVal = OutputDevice::LogicToLogic( aTxtRight, MapUnit::MapTwip, MapUnit::Map100thMM );
......
......@@ -217,7 +217,7 @@ void ParaLRSpacingWindow::SetValue(SfxItemState eState, const SfxPoolItem* pStat
&& m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Default)
&& m_aContext.GetCombinedContext_DI() != CombinedEnumContext(Application::WriterVariants, Context::Table))
{
m_pFLSpacing->SetMin(aTxtLeft*(-1), FUNIT_100TH_MM);
m_pFLSpacing->SetMin(aTxtLeft*-1, FUNIT_100TH_MM);
}
aTxtRight = (long)m_pAfterSpacing->Normalize(aTxtRight);
......
......@@ -1474,7 +1474,7 @@ static const SwCellFrame *lcl_FindFrame( const SwLayoutFrame *pLay, const Point
SwTwips& rPointX = aRectFnSet.IsVert() ? aPt.Y() : aPt.X();
SwTwips& rPointY = aRectFnSet.IsVert() ? aPt.X() : aPt.Y();
const SwTwips nXDiff = aRectFnSet.XDiff( nLeft, rPointX ) * ( bRTL ? (-1) : 1 );
const SwTwips nXDiff = aRectFnSet.XDiff( nLeft, rPointX ) * ( bRTL ? -1 : 1 );
const SwTwips nYDiff = aRectFnSet.YDiff( nTop, rPointY );
bCloseToRow = nXDiff >= 0 && nXDiff < nFuzzy;
......
......@@ -606,7 +606,7 @@ bool ChkChartSel( const SwNode& rSttNd, const SwNode& rEndNd )
aRectFnSet.GetLeft(rCF.pFrame->getFrameArea()) ) &&
nHeight == aRectFnSet.GetHeight(rCF.pFrame->getFrameArea()) )
{
nXPos += ( bRTL ? (-1) : 1 ) *
nXPos += ( bRTL ? -1 : 1 ) *
aRectFnSet.GetWidth(rCF.pFrame->getFrameArea());
++nCellCnt;
}
......@@ -1509,7 +1509,7 @@ static SwTwips lcl_CalcWish( const SwLayoutFrame *pCell, long nWish,
pTmp = static_cast<const SwLayoutFrame*>(pTmp->GetPrev());
sal_Int64 nTmp = pTmp->GetFormat()->GetFrameSize().GetWidth();
// multiply in 64-bit to avoid overflow here!
nRet += ( bRTL ? ( -1 ) : 1 ) * nTmp * nAct / nWish;
nRet += ( bRTL ? -1 : 1 ) * nTmp * nAct / nWish;
}
pTmp = pTmp->GetUpper()->GetUpper();
if ( pTmp && !pTmp->IsCellFrame() )
......
......@@ -2865,7 +2865,7 @@ void WW8TabDesc::FinishSwTable()
{
const long nRowSpanSet = (n == 0) && (i == 0) ?
nRowSpan :
((-1) * (nRowSpan - n));
(-1 * (nRowSpan - n));
SwTableBox* pCurrentBox = rRow[i];
pCurrentBox->setRowSpan(nRowSpanSet);
......
......@@ -229,7 +229,7 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
short int nFirstLineOffset = aParaMargin.GetTextFirstLineOfst();
aParaMargin.SetTextLeft( aParaMargin.GetTextLeft() + nFirstLineOffset );
aParaMargin.SetRight( aParaMargin.GetRight() );
aParaMargin.SetTextFirstLineOfst( nFirstLineOffset * (-1) );
aParaMargin.SetTextFirstLineOfst( nFirstLineOffset * -1 );
aNewAttr.Put(aParaMargin);
rReq.Done();
}
......
......@@ -662,7 +662,7 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
SvxLRSpaceItem aNewMargin( RES_LR_SPACE );
aNewMargin.SetTextLeft( aParaMargin.GetTextLeft() + aParaMargin.GetTextFirstLineOfst() );
aNewMargin.SetRight( aParaMargin.GetRight() );
aNewMargin.SetTextFirstLineOfst( (aParaMargin.GetTextFirstLineOfst()) * (-1) );
aNewMargin.SetTextFirstLineOfst( (aParaMargin.GetTextFirstLineOfst()) * -1 );
rSh.SetAttrItem( aNewMargin );
break;
......
......@@ -1327,7 +1327,7 @@ css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > VCLXToolkit::
{
css::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
if ( aDescr.ParentIndex == (-1) )
if ( aDescr.ParentIndex == -1 )
aDescr.Parent = nullptr;
else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) )
aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
......
......@@ -122,7 +122,7 @@ sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const OUString& rPropertyName
sal_Int32 UnoPropertyArrayHelper::getHandleByName( const OUString & rPropertyName )
{
sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName );
return nId ? nId : (-1);
return nId ? nId : -1;
}
sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const css::uno::Sequence< OUString > & rPropNames )
......
......@@ -80,7 +80,7 @@ namespace ftp {
FTPDirentry()
: m_aDate(),
m_nMode(INETCOREFTP_FILEMODE_UNKNOWN),
m_nSize((sal_uInt32)(-1)) { }
m_nSize((sal_uInt32)-1) { }
void clear() {
m_aURL.clear();
......
......@@ -1849,7 +1849,7 @@ void TextEngine::RecalcTextPortion( sal_uInt32 nPara, sal_Int32 nStartPos, sal_I
TETextPortion* const pTP = pTEParaPortion->GetTextPortions()[ nTP ];
SAL_WARN_IF( !pTP, "vcl", "RecalcTextPortion: Portion not found!" );
pTP->GetLen() += nNewChars;
pTP->GetWidth() = (-1);
pTP->GetWidth() = -1;
}
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment