[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang include/svtools svtools/source
Noel Grandin
noel.grandin at collabora.co.uk
Sun Apr 29 15:03:40 UTC 2018
compilerplugins/clang/test/useuniqueptr.cxx | 11 ++++++
compilerplugins/clang/useuniqueptr.cxx | 31 +++++++++++++++++
include/svtools/calendar.hxx | 9 +---
svtools/source/control/calendar.cxx | 51 +++++++---------------------
4 files changed, 59 insertions(+), 43 deletions(-)
New commits:
commit 89f470752d0ecc2a389aa8f630800a195a341a6d
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Apr 24 13:35:12 2018 +0200
loplugin:useuniqueptr in Calendar
and remove some unused fields
Change-Id: I66a40bae01a5186185383b1ec827d7da5d0b483e
Reviewed-on: https://gerrit.libreoffice.org/53592
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/svtools/calendar.hxx b/include/svtools/calendar.hxx
index b140ca01a64f..753ecad1f606 100644
--- a/include/svtools/calendar.hxx
+++ b/include/svtools/calendar.hxx
@@ -27,6 +27,7 @@
#include <vcl/ctrl.hxx>
#include <vcl/timer.hxx>
#include <vcl/field.hxx>
+#include <memory>
#include <set>
class MouseEvent;
@@ -124,8 +125,8 @@ typedef std::set<sal_Int32> IntDateSet;
class SVT_DLLPUBLIC Calendar final : public Control
{
- IntDateSet* mpSelectTable;
- IntDateSet* mpOldSelectTable;
+ std::unique_ptr<IntDateSet> mpSelectTable;
+ std::unique_ptr<IntDateSet> mpOldSelectTable;
OUString maDayTexts[31];
OUString maDayText;
OUString maWeekText;
@@ -144,9 +145,6 @@ class SVT_DLLPUBLIC Calendar final : public Control
Date maDropDate;
Color maSelColor;
Color maOtherColor;
- Color* mpStandardColor;
- Color* mpSaturdayColor;
- Color* mpSundayColor;
sal_Int32 mnDayCount;
long mnDaysOffX;
long mnWeekDayOffY;
@@ -188,7 +186,6 @@ class SVT_DLLPUBLIC Calendar final : public Control
SVT_DLLPRIVATE void ImplDrawSpin(vcl::RenderContext& rRenderContext);
SVT_DLLPRIVATE void ImplDrawDate(vcl::RenderContext& rRenderContext, long nX, long nY,
sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear,
- DayOfWeek eDayOfWeek,
bool bOther, sal_Int32 nToday);
SVT_DLLPRIVATE void ImplDraw(vcl::RenderContext& rRenderContext);
SVT_DLLPRIVATE void ImplUpdateDate( const Date& rDate );
diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx
index 3771de6a8f7d..57af295f0a6d 100644
--- a/svtools/source/control/calendar.cxx
+++ b/svtools/source/control/calendar.cxx
@@ -69,11 +69,7 @@ static void ImplCalendarSelectDate( IntDateSet* pTable, const Date& rDate, bool
void Calendar::ImplInit( WinBits nWinStyle )
{
- mpSelectTable = new IntDateSet;
- mpOldSelectTable = nullptr;
- mpStandardColor = nullptr;
- mpSaturdayColor = nullptr;
- mpSundayColor = nullptr;
+ mpSelectTable.reset(new IntDateSet);
mnDayCount = 0;
mnWinStyle = nWinStyle;
mnFirstYear = 0;
@@ -107,7 +103,7 @@ void Calendar::ImplInit( WinBits nWinStyle )
}
SetFirstDate( maCurDate );
- ImplCalendarSelectDate( mpSelectTable, maCurDate, true );
+ ImplCalendarSelectDate( mpSelectTable.get(), maCurDate, true );
// Sonstige Strings erzeugen
maDayText = SvtResId(STR_SVT_CALENDAR_DAY);
@@ -164,12 +160,8 @@ Calendar::~Calendar()
void Calendar::dispose()
{
- delete mpStandardColor;
- delete mpSaturdayColor;
- delete mpSundayColor;
-
- delete mpSelectTable;
- delete mpOldSelectTable;
+ mpSelectTable.reset();
+ mpOldSelectTable.reset();
Control::dispose();
}
@@ -544,10 +536,9 @@ void Calendar::ImplDrawSpin(vcl::RenderContext& rRenderContext )
void Calendar::ImplDrawDate(vcl::RenderContext& rRenderContext,
long nX, long nY,
sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear,
- DayOfWeek eDayOfWeek,
bool bOther, sal_Int32 nToday )
{
- Color* pTextColor = nullptr;
+ Color const * pTextColor = nullptr;
const OUString& rDay = maDayTexts[nDay - 1];
tools::Rectangle aDateRect(nX, nY, nX + mnDayWidth - 1, nY + mnDayHeight - 1);
@@ -571,15 +562,6 @@ void Calendar::ImplDrawDate(vcl::RenderContext& rRenderContext,
pTextColor = &maSelColor;
else if (bOther)
pTextColor = &maOtherColor;
- else
- {
- if (eDayOfWeek == SATURDAY)
- pTextColor = mpSaturdayColor;
- else if (eDayOfWeek == SUNDAY)
- pTextColor = mpSundayColor;
- if (!pTextColor)
- pTextColor = mpStandardColor;
- }
if (bFocus)
HideFocus();
@@ -756,14 +738,13 @@ void Calendar::ImplDraw(vcl::RenderContext& rRenderContext)
nDeltaX = nDayX + (nDay * mnDayWidth);
ImplDrawDate(rRenderContext, nDeltaX, nDayY, nDay + aTempDate.GetDay(),
aTempDate.GetMonth(), aTempDate.GetYear(),
- static_cast<DayOfWeek>((nDay + static_cast<sal_uInt16>(eStartDay)) % 7), true, nToday);
+ true, nToday);
}
}
for (nDay = 1; nDay <= nDaysInMonth; nDay++)
{
nDeltaX = nDayX + (nDayIndex * mnDayWidth);
ImplDrawDate(rRenderContext, nDeltaX, nDayY, nDay, nMonth, nYear,
- static_cast<DayOfWeek>((nDayIndex + static_cast<sal_uInt16>(eStartDay)) % 7),
false, nToday);
if (nDayIndex == 6)
{
@@ -785,7 +766,6 @@ void Calendar::ImplDraw(vcl::RenderContext& rRenderContext)
nDeltaX = nDayX + (nDayIndex * mnDayWidth);
ImplDrawDate(rRenderContext, nDeltaX, nDayY, nDay,
aTempDate.GetMonth(), aTempDate.GetYear(),
- static_cast<DayOfWeek>((nDayIndex + static_cast<sal_uInt16>(eStartDay)) % 7),
true, nToday);
if (nDayIndex == 6)
{
@@ -822,7 +802,7 @@ void Calendar::ImplUpdateDate( const Date& rDate )
void Calendar::ImplUpdateSelection( IntDateSet* pOld )
{
- IntDateSet* pNew = mpSelectTable;
+ IntDateSet* pNew = mpSelectTable.get();
for (auto const& nKey : *pOld)
{
@@ -860,8 +840,8 @@ void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest,
if ( aTempDate != maCurDate )
{
maCurDate = aTempDate;
- ImplCalendarSelectDate( mpSelectTable, aOldDate, false );
- ImplCalendarSelectDate( mpSelectTable, maCurDate, true );
+ ImplCalendarSelectDate( mpSelectTable.get(), aOldDate, false );
+ ImplCalendarSelectDate( mpSelectTable.get(), maCurDate, true );
}
bool bNewSel = *pOldSel != *mpSelectTable;
@@ -1048,8 +1028,7 @@ void Calendar::ImplEndTracking( bool bCancel )
if ( !bSelection && (mnWinStyle & WB_TABSTOP) && !bCancel )
GrabFocus();
- delete mpOldSelectTable;
- mpOldSelectTable = nullptr;
+ mpOldSelectTable.reset();
}
IMPL_LINK_NOARG( Calendar, ScrollHdl, Timer*, void )
@@ -1091,9 +1070,8 @@ void Calendar::MouseButtonDown( const MouseEvent& rMEvt )
{
if ( (rMEvt.GetClicks() != 2) || !(nHitTest & CALENDAR_HITTEST_DAY) )
{
- delete mpOldSelectTable;
maOldCurDate = maCurDate;
- mpOldSelectTable = new IntDateSet( *mpSelectTable );
+ mpOldSelectTable.reset(new IntDateSet( *mpSelectTable ));
if ( !mbSelection )
{
@@ -1359,8 +1337,8 @@ void Calendar::SetCurDate( const Date& rNewDate )
maCurDate = rNewDate;
maAnchorDate = maCurDate;
- ImplCalendarSelectDate( mpSelectTable, aOldDate, false );
- ImplCalendarSelectDate( mpSelectTable, maCurDate, true );
+ ImplCalendarSelectDate( mpSelectTable.get(), aOldDate, false );
+ ImplCalendarSelectDate( mpSelectTable.get(), maCurDate, true );
// shift actual date in the visible area
if ( mbFormat || (maCurDate < GetFirstMonth()) )
@@ -1553,9 +1531,8 @@ tools::Rectangle Calendar::GetDateRect( const Date& rDate ) const
void Calendar::StartSelection()
{
- delete mpOldSelectTable;
maOldCurDate = maCurDate;
- mpOldSelectTable = new IntDateSet( *mpSelectTable );
+ mpOldSelectTable.reset(new IntDateSet( *mpSelectTable ));
mbSelection = true;
}
commit a369e6bbd539caf59ccbb10d374c8aeab72054db
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Apr 24 14:04:53 2018 +0200
loplugin:useuniqueptr look for DELETEZ expressions
can't believe I've been missing these
Change-Id: If39827e1583cbcedfd5061a5059d6df53be0f9c8
Reviewed-on: https://gerrit.libreoffice.org/53598
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx
index ef0dde3cf538..a68cea3201d0 100644
--- a/compilerplugins/clang/test/useuniqueptr.cxx
+++ b/compilerplugins/clang/test/useuniqueptr.cxx
@@ -151,4 +151,15 @@ class Foo12 {
delete m_pbar[i++]; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}}
}
};
+#define DELETEZ( p ) ( delete p,p = NULL )
+class Foo13 {
+ int * m_pbar1; // expected-note {{member is here [loplugin:useuniqueptr]}}
+ int * m_pbar2; // expected-note {{member is here [loplugin:useuniqueptr]}}
+ ~Foo13()
+ {
+ if (m_pbar1)
+ DELETEZ(m_pbar1); // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
+ DELETEZ(m_pbar2); // expected-error {{unconditional call to delete on a member, should be using std::unique_ptr [loplugin:useuniqueptr]}}
+ }
+};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 0b5fb2c79aa7..0aab2a644bfb 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -58,6 +58,7 @@ private:
void CheckLoopDelete(const CXXMethodDecl*, const Stmt* );
void CheckLoopDelete(const CXXMethodDecl*, const CXXDeleteExpr* );
void CheckDeleteExpr(const CXXMethodDecl*, const CXXDeleteExpr*);
+ void CheckParenExpr(const CXXMethodDecl*, const ParenExpr*);
void CheckDeleteExpr(const CXXMethodDecl*, const CXXDeleteExpr*,
const MemberExpr*, StringRef message);
};
@@ -101,6 +102,12 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXMethodDecl* methodDecl, const C
CheckDeleteExpr(methodDecl, deleteExpr);
continue;
}
+ auto parenExpr = dyn_cast<ParenExpr>(*i);
+ if (parenExpr)
+ {
+ CheckParenExpr(methodDecl, parenExpr);
+ continue;
+ }
// Check for conditional deletes like:
// if (m_pField != nullptr) delete m_pField;
auto ifStmt = dyn_cast<IfStmt>(*i);
@@ -132,6 +139,13 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXMethodDecl* methodDecl, const C
continue;
}
+ parenExpr = dyn_cast<ParenExpr>(ifStmt->getThen());
+ if (parenExpr)
+ {
+ CheckParenExpr(methodDecl, parenExpr);
+ continue;
+ }
+
auto ifThenCompoundStmt = dyn_cast<CompoundStmt>(ifStmt->getThen());
if (!ifThenCompoundStmt)
continue;
@@ -140,6 +154,9 @@ void UseUniquePtr::CheckForSimpleDelete(const CXXMethodDecl* methodDecl, const C
auto ifDeleteExpr = dyn_cast<CXXDeleteExpr>(*j);
if (ifDeleteExpr)
CheckDeleteExpr(methodDecl, ifDeleteExpr);
+ ParenExpr const * parenExpr = dyn_cast<ParenExpr>(*i);
+ if (parenExpr)
+ CheckParenExpr(methodDecl, parenExpr);
}
}
}
@@ -160,6 +177,20 @@ void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDel
}
/**
+ * Look for DELETEZ expressions.
+ */
+void UseUniquePtr::CheckParenExpr(const CXXMethodDecl* methodDecl, const ParenExpr* parenExpr)
+{
+ auto binaryOp = dyn_cast<BinaryOperator>(parenExpr->getSubExpr());
+ if (!binaryOp || binaryOp->getOpcode() != BO_Comma)
+ return;
+ auto deleteExpr = dyn_cast<CXXDeleteExpr>(binaryOp->getLHS());
+ if (!deleteExpr)
+ return;
+ CheckDeleteExpr(methodDecl, deleteExpr);
+}
+
+/**
* Check the delete expression in a destructor.
*/
void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDeleteExpr* deleteExpr,
More information about the Libreoffice-commits
mailing list