Kaydet (Commit) 4f4486c6 authored tarafından Noel Grandin's avatar Noel Grandin

look for =() in loplugin:unnecessaryparen

Change-Id: I4f9b71ff7767e90987bb40358fc46ed5d1d571d0
Reviewed-on: https://gerrit.libreoffice.org/44944Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst fda2ee3d
......@@ -161,7 +161,7 @@ DataLabelResources::DataLabelResources(VclBuilderContainer* pWindow, vcl::Window
if( rInAttrs.GetItemState(SCHATTR_DATADESCR_NO_PERCENTVALUE, true, &pPoolItem) == SfxItemState::SET )
{
bool bForbidPercentValue = (static_cast< const SfxBoolItem & >( rInAttrs.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE )).GetValue() );
bool bForbidPercentValue = static_cast< const SfxBoolItem & >( rInAttrs.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE )).GetValue();
if( bForbidPercentValue )
m_pCBPercent->Enable(false);
}
......
......@@ -232,7 +232,7 @@ void ErrorBarResources::UpdateControlStates()
// range buttons
m_pRbRange->Enable( !m_bHasInternalDataProvider || m_bEnableDataTableDialog );
bool bShowRange = ( m_pRbRange->IsChecked());
bool bShowRange = m_pRbRange->IsChecked();
bool bCanChooseRange =
( bShowRange &&
m_apRangeSelectionHelper.get() &&
......
......@@ -549,8 +549,8 @@ bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet
case SCHATTR_AXIS_REVERSE:
{
bool bWasReverse = ( aScale.Orientation == AxisOrientation_REVERSE );
bool bNewReverse = (static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue() );
bool bNewReverse = static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue();
if( bWasReverse != bNewReverse )
{
aScale.Orientation = bNewReverse ? AxisOrientation_REVERSE : AxisOrientation_MATHEMATICAL;
......@@ -891,8 +891,8 @@ bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet
if( m_pExplicitScale )
{
bool bUseSourceFormat =
(static_cast< const SfxBoolItem & >(
rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
static_cast< const SfxBoolItem & >(
rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue();
if( ! bUseSourceFormat )
{
......@@ -914,8 +914,8 @@ bool AxisItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet
case SID_ATTR_NUMBERFORMAT_SOURCE:
{
bool bUseSourceFormat =
(static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue() );
static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue();
GetPropertySet()->setPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT, uno::Any(bUseSourceFormat));
bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT).hasValue();
......
......@@ -104,8 +104,8 @@ bool lcl_NumberFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSe
return bChanged;
uno::Any aValue;
bool bUseSourceFormat = (static_cast< const SfxBoolItem & >(
rItemSet.Get( nSourceWhich )).GetValue() );
bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
rItemSet.Get( nSourceWhich )).GetValue();
if( !bUseSourceFormat )
{
SfxItemState aState = rItemSet.GetItemState( nWhichId );
......@@ -151,8 +151,8 @@ bool lcl_UseSourceFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxIte
return bChanged;
uno::Any aNewValue;
bool bUseSourceFormat = (static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue() );
bool bUseSourceFormat = static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue();
if( !bUseSourceFormat )
{
SfxItemState aState = rItemSet.GetItemState( nFormatWhich );
......@@ -601,7 +601,7 @@ void DataPointItemConverter::FillSpecialItem(
break;
case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE:
{
bool bNumberFormatIsSet = ( GetPropertySet()->getPropertyValue( "PercentageNumberFormat" ).hasValue());
bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue( "PercentageNumberFormat" ).hasValue();
rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
}
break;
......
......@@ -84,9 +84,9 @@ void ItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
while( (*pRanges) != 0)
{
sal_uInt16 nBeg = (*pRanges);
sal_uInt16 nBeg = *pRanges;
++pRanges;
sal_uInt16 nEnd = (*pRanges);
sal_uInt16 nEnd = *pRanges;
++pRanges;
OSL_ASSERT( nBeg <= nEnd );
......
......@@ -295,8 +295,8 @@ bool SeriesOptionsItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const Sf
case SCHATTR_CLOCKWISE:
{
bool bClockwise = (static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue() );
bool bClockwise = static_cast< const SfxBoolItem & >(
rItemSet.Get( nWhichId )).GetValue();
if( m_xCooSys.is() )
{
uno::Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1, 0, m_xCooSys ) );
......
......@@ -96,7 +96,7 @@ bool numberFormatFromItemToPropertySet(
return bChanged;
uno::Any aValue;
bool bUseSourceFormat = (static_cast<const SfxBoolItem&>(rItemSet.Get(nSourceWhich)).GetValue());
bool bUseSourceFormat = static_cast<const SfxBoolItem&>(rItemSet.Get(nSourceWhich)).GetValue();
if (!bUseSourceFormat)
{
SfxItemState aState = rItemSet.GetItemState(nWhichId);
......@@ -144,8 +144,8 @@ bool useSourceFormatFromItemToPropertySet(
return bChanged;
uno::Any aNewValue;
bool bUseSourceFormat = (static_cast<const SfxBoolItem&>(
rItemSet.Get(nWhichId)).GetValue());
bool bUseSourceFormat = static_cast<const SfxBoolItem&>(
rItemSet.Get(nWhichId)).GetValue();
if (!bUseSourceFormat)
{
SfxItemState aState = rItemSet.GetItemState(nFormatWhich);
......@@ -550,7 +550,7 @@ void TextLabelItemConverter::FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet& r
break;
case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE:
{
bool bNumberFormatIsSet = (GetPropertySet()->getPropertyValue("PercentageNumberFormat").hasValue());
bool bNumberFormatIsSet = GetPropertySet()->getPropertyValue("PercentageNumberFormat").hasValue();
rOutItemSet.Put(SfxBoolItem(nWhichId, !bNumberFormatIsSet));
}
break;
......
......@@ -432,7 +432,7 @@ void ImplObjectHierarchy::createDataSeriesTree(
if( DataSeriesHelper::hasDataLabelsAtSeries( xSeries ) )
{
OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) );
aChildParticle+=("=");
aChildParticle += "=";
aSeriesSubContainer.emplace_back( ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle ) );
}
......
......@@ -2444,7 +2444,7 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntriesForSeries(
}
// label
aLabelText = ( DataSeriesHelper::getDataSeriesLabel( rSeries.getModel(), m_xChartTypeModel.is() ? m_xChartTypeModel->getRoleOfSequenceForSeriesLabel() : "values-y") );
aLabelText = DataSeriesHelper::getDataSeriesLabel( rSeries.getModel(), m_xChartTypeModel.is() ? m_xChartTypeModel->getRoleOfSequenceForSeriesLabel() : "values-y");
aEntry.aLabel = FormattedStringHelper::createFormattedStringSequence( xContext, aLabelText, xTextProperties );
aResult.push_back(aEntry);
......
......@@ -789,8 +789,8 @@ DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
tools::Rectangle aRect;
pDevice->SetFont(aFont);
pDevice->GetTextBoundRect(aRect, rText);
int screenWidth = (aRect.BottomRight().X());
int screenHeight = (aRect.BottomRight().Y());
int screenWidth = aRect.BottomRight().X();
int screenHeight = aRect.BottomRight().Y();
pDevice->SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
pDevice->DrawText(Point(0, 0), rText);
......
......@@ -7,6 +7,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <string>
#include <rtl/ustring.hxx>
bool foo(int);
enum class EFoo { Bar };
......@@ -20,7 +23,7 @@ int main()
foo((1)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
int y = (x); // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}}
int y = (x); // expected-error {{unnecessary parentheses around identifier [loplugin:unnecessaryparen]}} expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
(void)y;
EFoo foo = EFoo::Bar;
......@@ -40,6 +43,13 @@ int main()
return 0;
}
x = (true) ? 0 : 1;
int v2 = (1); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
(void)v2;
std::string v3;
v3 = (std::string("xx") + "xx"); // expected-error {{parentheses immediately inside assignment [loplugin:unnecessaryparen]}}
(void)v3;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -79,11 +79,13 @@ public:
bool VisitCaseStmt(const CaseStmt *);
bool VisitReturnStmt(const ReturnStmt* );
bool VisitCallExpr(const CallExpr *);
bool VisitVarDecl(const VarDecl *);
bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *);
bool TraverseUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *);
bool TraverseCaseStmt(CaseStmt *);
bool TraverseConditionalOperator(ConditionalOperator *);
private:
void VisitSomeStmt(const Stmt *parent, const Expr* cond, StringRef stmtName);
void VisitSomeStmt(Stmt const * stmt, const Expr* cond, StringRef stmtName);
Expr const * insideSizeof = nullptr;
Expr const * insideCaseStmt = nullptr;
Expr const * insideConditionalOperator = nullptr;
......@@ -234,11 +236,11 @@ bool UnnecessaryParen::VisitReturnStmt(const ReturnStmt* returnStmt)
return true;
}
void UnnecessaryParen::VisitSomeStmt(const Stmt *parent, const Expr* cond, StringRef stmtName)
void UnnecessaryParen::VisitSomeStmt(const Stmt * stmt, const Expr* cond, StringRef stmtName)
{
if (ignoreLocation(parent))
if (ignoreLocation(stmt))
return;
if (parent->getLocStart().isMacroID())
if (stmt->getLocStart().isMacroID())
return;
auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(cond));
......@@ -273,18 +275,90 @@ bool UnnecessaryParen::VisitCallExpr(const CallExpr* callExpr)
return true;
auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(callExpr->getArg(0)));
if (parenExpr) {
if (parenExpr->getLocStart().isMacroID())
return true;
// assignments need extra parentheses or they generate a compiler warning
auto binaryOp = dyn_cast<BinaryOperator>(parenExpr->getSubExpr());
if (binaryOp && binaryOp->getOpcode() == BO_Assign)
return true;
report(
DiagnosticsEngine::Warning, "parentheses immediately inside single-arg call",
parenExpr->getLocStart())
<< parenExpr->getSourceRange();
}
if (!parenExpr)
return true;
if (parenExpr->getLocStart().isMacroID())
return true;
// assignments need extra parentheses or they generate a compiler warning
auto binaryOp = dyn_cast<BinaryOperator>(parenExpr->getSubExpr());
if (binaryOp && binaryOp->getOpcode() == BO_Assign)
return true;
report(
DiagnosticsEngine::Warning, "parentheses immediately inside single-arg call",
parenExpr->getLocStart())
<< parenExpr->getSourceRange();
return true;
}
bool UnnecessaryParen::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr* callExpr)
{
if (ignoreLocation(callExpr))
return true;
if (callExpr->getLocStart().isMacroID())
return true;
if (callExpr->getNumArgs() != 2)
return true;
// Same logic as CXXOperatorCallExpr::isAssignmentOp(), which our supported clang
// doesn't have yet.
auto Opc = callExpr->getOperator();
if (Opc != OO_Equal && Opc != OO_StarEqual &&
Opc != OO_SlashEqual && Opc != OO_PercentEqual &&
Opc != OO_PlusEqual && Opc != OO_MinusEqual &&
Opc != OO_LessLessEqual && Opc != OO_GreaterGreaterEqual &&
Opc != OO_AmpEqual && Opc != OO_CaretEqual &&
Opc != OO_PipeEqual)
return true;
auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(callExpr->getArg(1)));
if (!parenExpr)
return true;
if (parenExpr->getLocStart().isMacroID())
return true;
// Sometimes parentheses make the RHS of an assignment easier to read by
// visually disambiguating the = from a call to ==
auto sub = parenExpr->getSubExpr();
if (isa<BinaryOperator>(sub)
|| isa<CXXOperatorCallExpr>(sub)
|| isa<ConditionalOperator>(sub))
return true;
report(
DiagnosticsEngine::Warning, "parentheses immediately inside assignment",
parenExpr->getLocStart())
<< parenExpr->getSourceRange();
return true;
}
bool UnnecessaryParen::VisitVarDecl(const VarDecl* varDecl)
{
if (ignoreLocation(varDecl))
return true;
if (varDecl->getLocStart().isMacroID())
return true;
if (!varDecl->getInit())
return true;
auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(varDecl->getInit()));
if (!parenExpr)
return true;
if (parenExpr->getLocStart().isMacroID())
return true;
auto sub = parenExpr->getSubExpr();
if (isa<BinaryOperator>(sub)
|| isa<CXXOperatorCallExpr>(sub)
|| isa<ConditionalOperator>(sub)
// these two are for "parentheses were disambiguated as a function declaration [-Werror,-Wvexing-parse]"
|| isa<CXXBindTemporaryExpr>(sub)
|| isa<CXXFunctionalCastExpr>(sub))
return true;
//varDecl->dump();
report(
DiagnosticsEngine::Warning, "parentheses immediately inside vardecl statement",
parenExpr->getLocStart())
<< parenExpr->getSourceRange();
return true;
}
......
......@@ -374,8 +374,8 @@ static std::vector< OUString > lookupKeys(
if( keySupplier.is() )
{
Reference< XPropertySet > set( keySupplier, UNO_QUERY );
set->getPropertyValue( getStatics().NAME ) >>= (*pTable);
set->getPropertyValue( getStatics().SCHEMA_NAME ) >>= (*pSchema );
set->getPropertyValue( getStatics().NAME ) >>= *pTable;
set->getPropertyValue( getStatics().SCHEMA_NAME ) >>= *pSchema;
set.clear();
Reference< XEnumerationAccess > keys ( keySupplier->getKeys(), UNO_QUERY );
......
......@@ -2102,7 +2102,7 @@ void ExtensionsTabPage::CreateDialogWithHandler()
{
try
{
bool bWithHandler = ( !m_sEventHdl.isEmpty() );
bool bWithHandler = !m_sEventHdl.isEmpty();
if ( bWithHandler )
{
Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
......
......@@ -693,7 +693,7 @@ void ORowSet::updateValue(sal_Int32 columnIndex,const ORowSetValue& x)
checkUpdateConditions(columnIndex);
checkUpdateIterator();
ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
ORowSetValueVector::Vector& rRow = (*m_aCurrentRow)->get();
ORowSetNotifier aNotify(