summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-12-10 17:33:54 +0100
committerStephan Bergmann <sbergman@redhat.com>2015-12-10 17:34:31 +0100
commit4a1edf626ad48b5955892e5590d75fa7ae5eaf58 (patch)
tree3ace4c2ac4da5529295780880f67fdfce09b6637
parent46fe3bddebf30775ae19eaa0fefe1d8e2f78eced (diff)
More loplugin:nullptr automatic rewrite (within templates)
Change-Id: I9bc06cfb5eeb38fd7ae7fb25f876ea9f96e4a65a
-rw-r--r--basegfx/source/inc/hommatrixtemplate.hxx2
-rw-r--r--bridges/source/cpp_uno/shared/guardedarray.hxx2
-rw-r--r--compilerplugins/clang/store/nullptr.cxx68
-rw-r--r--include/com/sun/star/uno/Reference.h2
-rw-r--r--include/com/sun/star/uno/Reference.hxx8
-rw-r--r--include/rtl/ref.hxx8
-rw-r--r--include/salhelper/dynload.hxx2
-rw-r--r--include/salhelper/singletonref.hxx2
-rw-r--r--include/sfx2/itemconnect.hxx2
-rw-r--r--include/tools/ref.hxx20
-rw-r--r--include/tools/weakbase.hxx4
-rw-r--r--sal/rtl/math.cxx4
-rw-r--r--stoc/source/security/lru_cache.h2
-rw-r--r--store/source/storbase.hxx10
-rw-r--r--sw/source/filter/ww8/writerwordglue.cxx4
15 files changed, 104 insertions, 36 deletions
diff --git a/basegfx/source/inc/hommatrixtemplate.hxx b/basegfx/source/inc/hommatrixtemplate.hxx
index 58a3b46990c4..76dc8a525801 100644
--- a/basegfx/source/inc/hommatrixtemplate.hxx
+++ b/basegfx/source/inc/hommatrixtemplate.hxx
@@ -200,7 +200,7 @@ namespace basegfx
if(!bNecessary)
{
delete mpLine;
- mpLine = 0L;
+ mpLine = nullptr;
}
}
}
diff --git a/bridges/source/cpp_uno/shared/guardedarray.hxx b/bridges/source/cpp_uno/shared/guardedarray.hxx
index ad5d6bdaa4c1..13e6f162260e 100644
--- a/bridges/source/cpp_uno/shared/guardedarray.hxx
+++ b/bridges/source/cpp_uno/shared/guardedarray.hxx
@@ -30,7 +30,7 @@ public:
T * get() const { return pointer; }
- T * release() { T * p = pointer; pointer = 0; return p; }
+ T * release() { T * p = pointer; pointer = nullptr; return p; }
private:
GuardedArray(GuardedArray &) = delete;
diff --git a/compilerplugins/clang/store/nullptr.cxx b/compilerplugins/clang/store/nullptr.cxx
index 8bed1ce40424..6bf4e54d3f15 100644
--- a/compilerplugins/clang/store/nullptr.cxx
+++ b/compilerplugins/clang/store/nullptr.cxx
@@ -44,6 +44,12 @@ public:
bool VisitGNUNullExpr(GNUNullExpr const * expr);
+ bool VisitBinaryOperator(BinaryOperator const * expr);
+
+ bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr);
+
+ // bool shouldVisitTemplateInstantiations() const { return true; }
+
private:
bool isInLokIncludeFile(SourceLocation spellingLocation) const;
@@ -111,6 +117,68 @@ bool Nullptr::VisitGNUNullExpr(GNUNullExpr const * expr) {
return true;
}
+bool Nullptr::VisitBinaryOperator(BinaryOperator const * expr) {
+ if (ignoreLocation(expr)) {
+ return true;
+ }
+ Expr const * e;
+ switch (expr->getOpcode()) {
+ case BO_EQ:
+ case BO_NE:
+ if (expr->getRHS()->getType()->isPointerType()) {
+ e = expr->getLHS();
+ break;
+ }
+ // fall through
+ case BO_Assign:
+ if (expr->getLHS()->getType()->isPointerType()) {
+ e = expr->getRHS();
+ break;
+ }
+ // fall through
+ default:
+ return true;
+ }
+ //TODO: detect NPCK_ZeroExpression where appropriate
+ auto const lit = dyn_cast<IntegerLiteral>(e->IgnoreParenImpCasts());
+ if (lit == nullptr || lit->getValue().getBoolValue()) {
+ return true;
+ }
+ handleNull(e, nullptr, Expr::NPCK_ZeroLiteral);
+ return true;
+}
+
+bool Nullptr::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) {
+ if (ignoreLocation(expr)) {
+ return true;
+ }
+ Expr const * e;
+ switch (expr->getOperator()) {
+ case OO_EqualEqual:
+ case OO_ExclaimEqual:
+ if (expr->getArg(1)->getType()->isPointerType()) {
+ e = expr->getArg(0);
+ break;
+ }
+ // fall through
+ case OO_Equal:
+ if (expr->getArg(0)->getType()->isPointerType()) {
+ e = expr->getArg(1);
+ break;
+ }
+ // fall through
+ default:
+ return true;
+ }
+ //TODO: detect NPCK_ZeroExpression where appropriate
+ auto const lit = dyn_cast<IntegerLiteral>(e->IgnoreParenImpCasts());
+ if (lit == nullptr || lit->getValue().getBoolValue()) {
+ return true;
+ }
+ handleNull(e, nullptr, Expr::NPCK_ZeroLiteral);
+ return true;
+}
+
bool Nullptr::isInLokIncludeFile(SourceLocation spellingLocation) const {
return compiler.getSourceManager().getFilename(spellingLocation)
.startswith(SRCDIR "/include/LibreOfficeKit/");
diff --git a/include/com/sun/star/uno/Reference.h b/include/com/sun/star/uno/Reference.h
index 8e266cd72f43..368c9982a2fd 100644
--- a/include/com/sun/star/uno/Reference.h
+++ b/include/com/sun/star/uno/Reference.h
@@ -408,7 +408,7 @@ public:
@return UNacquired interface pointer
*/
inline interface_type * SAL_CALL operator -> () const {
- assert(_pInterface != 0);
+ assert(_pInterface != NULL);
return castFromXInterface(_pInterface);
}
diff --git a/include/com/sun/star/uno/Reference.hxx b/include/com/sun/star/uno/Reference.hxx
index b25083d8e030..f7a713196eaa 100644
--- a/include/com/sun/star/uno/Reference.hxx
+++ b/include/com/sun/star/uno/Reference.hxx
@@ -113,7 +113,7 @@ inline Reference< interface_type >::~Reference()
template< class interface_type >
inline Reference< interface_type >::Reference()
{
- _pInterface = 0;
+ _pInterface = NULL;
}
template< class interface_type >
@@ -221,7 +221,7 @@ inline void Reference< interface_type >::clear()
if (_pInterface)
{
XInterface * const pOld = _pInterface;
- _pInterface = 0;
+ _pInterface = NULL;
pOld->release();
}
}
@@ -236,7 +236,7 @@ inline bool Reference< interface_type >::set(
_pInterface = castToXInterface(pInterface);
if (pOld)
pOld->release();
- return (0 != pInterface);
+ return (NULL != pInterface);
}
template< class interface_type >
@@ -247,7 +247,7 @@ inline bool Reference< interface_type >::set(
_pInterface = castToXInterface(pInterface);
if (pOld)
pOld->release();
- return (0 != pInterface);
+ return (NULL != pInterface);
}
template< class interface_type >
diff --git a/include/rtl/ref.hxx b/include/rtl/ref.hxx
index 3ffcfc049c15..ea219cdae77b 100644
--- a/include/rtl/ref.hxx
+++ b/include/rtl/ref.hxx
@@ -153,7 +153,7 @@ public:
if (m_pBody)
{
reference_type * const pOld = m_pBody;
- m_pBody = 0;
+ m_pBody = NULL;
pOld->release();
}
return *this;
@@ -174,7 +174,7 @@ public:
*/
inline reference_type * SAL_CALL operator->() const
{
- assert(m_pBody != 0);
+ assert(m_pBody != NULL);
return m_pBody;
}
@@ -183,7 +183,7 @@ public:
*/
inline reference_type & SAL_CALL operator*() const
{
- assert(m_pBody != 0);
+ assert(m_pBody != NULL);
return *m_pBody;
}
@@ -192,7 +192,7 @@ public:
*/
inline bool SAL_CALL is() const
{
- return (m_pBody != 0);
+ return (m_pBody != NULL);
}
diff --git a/include/salhelper/dynload.hxx b/include/salhelper/dynload.hxx
index 91d70c12d2a6..b5b16fae4638 100644
--- a/include/salhelper/dynload.hxx
+++ b/include/salhelper/dynload.hxx
@@ -108,7 +108,7 @@ public:
/// Default constructor
ODynamicLoader()
{
- m_pLoader = 0;
+ m_pLoader = NULL;
}
/** Constructor, loads the library if necessary otherwise the refernece count will
diff --git a/include/salhelper/singletonref.hxx b/include/salhelper/singletonref.hxx
index 84064be2a0ce..52e54a513dc5 100644
--- a/include/salhelper/singletonref.hxx
+++ b/include/salhelper/singletonref.hxx
@@ -128,7 +128,7 @@ class SingletonRef
if (m_nRef == 0)
{
delete m_pInstance;
- m_pInstance = 0;
+ m_pInstance = NULL;
}
// <- GLOBAL SAFE
}
diff --git a/include/sfx2/itemconnect.hxx b/include/sfx2/itemconnect.hxx
index c0cf7a62b093..ae265b752497 100644
--- a/include/sfx2/itemconnect.hxx
+++ b/include/sfx2/itemconnect.hxx
@@ -473,7 +473,7 @@ template< typename ItemWrpT, typename ControlWrpT >
void ItemControlConnection< ItemWrpT, ControlWrpT >::Reset( const SfxItemSet& rItemSet )
{
const ItemType* pItem = maItemWrp.GetUniqueItem( rItemSet );
- mxCtrlWrp->SetControlDontKnow( pItem == 0 );
+ mxCtrlWrp->SetControlDontKnow( pItem == nullptr );
if( pItem )
mxCtrlWrp->SetControlValue( maItemWrp.GetItemValue( *pItem ) );
}
diff --git a/include/tools/ref.hxx b/include/tools/ref.hxx
index 9cd1bf550f3e..2ca5def8d543 100644
--- a/include/tools/ref.hxx
+++ b/include/tools/ref.hxx
@@ -36,24 +36,24 @@ public:
SvRef(SvRef const & rObj): pObj(rObj.pObj)
{
- if (pObj != 0) pObj->AddNextRef();
+ if (pObj != nullptr) pObj->AddNextRef();
}
SvRef(T * pObjP): pObj(pObjP)
{
- if (pObj != 0) pObj->AddFirstRef();
+ if (pObj != nullptr) pObj->AddFirstRef();
}
~SvRef()
{
- if (pObj != 0) pObj->ReleaseRef();
+ if (pObj != nullptr) pObj->ReleaseRef();
}
void Clear()
{
- if (pObj != 0) {
+ if (pObj != nullptr) {
T * pRefObj = pObj;
- pObj = 0;
+ pObj = nullptr;
pRefObj->ReleaseRef();
}
}
@@ -65,21 +65,21 @@ public:
}
T * pRefObj = pObj;
pObj = rObj.pObj;
- if (pRefObj != 0) {
+ if (pRefObj != nullptr) {
pRefObj->ReleaseRef();
}
return *this;
}
- bool Is() const { return pObj != 0; }
+ bool Is() const { return pObj != nullptr; }
T * get() const { return pObj; }
T * operator &() const { return pObj; }
- T * operator ->() const { assert(pObj != 0); return pObj; }
+ T * operator ->() const { assert(pObj != nullptr); return pObj; }
- T & operator *() const { assert(pObj != 0); return *pObj; }
+ T & operator *() const { assert(pObj != nullptr); return *pObj; }
operator T *() const { return pObj; }
@@ -157,7 +157,7 @@ class SvCompatWeakHdl : public SvRefBase
SvCompatWeakHdl( T* pObj ) : _pObj( pObj ) {}
public:
- void ResetWeakBase( ) { _pObj = 0; }
+ void ResetWeakBase( ) { _pObj = nullptr; }
T* GetObj() { return _pObj; }
};
diff --git a/include/tools/weakbase.hxx b/include/tools/weakbase.hxx
index 652ea45d50d6..4087160409a3 100644
--- a/include/tools/weakbase.hxx
+++ b/include/tools/weakbase.hxx
@@ -137,7 +137,7 @@ inline WeakReference<reference_type>& WeakReference<reference_type>::operator= (
template< class reference_type >
inline WeakBase< reference_type >::WeakBase()
{
- mpWeakConnection = 0;
+ mpWeakConnection = nullptr;
}
template< class reference_type >
@@ -147,7 +147,7 @@ inline WeakBase< reference_type >::~WeakBase()
{
mpWeakConnection->mpReference = 0;
mpWeakConnection->release();
- mpWeakConnection = 0;
+ mpWeakConnection = nullptr;
}
}
diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx
index fd33130706e1..be8ebbe0137b 100644
--- a/sal/rtl/math.cxx
+++ b/sal/rtl/math.cxx
@@ -296,7 +296,7 @@ inline void doubleToString(StringT ** pResult,
{
pBuf = static_cast< typename T::Char * >(
rtl_allocateMemory(nBuf * sizeof (typename T::Char)));
- OSL_ENSURE(pBuf != 0, "Out of memory");
+ OSL_ENSURE(pBuf != nullptr, "Out of memory");
}
else
pBuf = aBuf;
@@ -787,7 +787,7 @@ inline double stringToDouble(CharT const * pBegin, CharT const * pEnd,
if (pStatus != nullptr)
*pStatus = eStatus;
- if (pParsedEnd != 0)
+ if (pParsedEnd != nullptr)
*pParsedEnd = p == p0 ? pBegin : p;
return fVal;
diff --git a/stoc/source/security/lru_cache.h b/stoc/source/security/lru_cache.h
index 51459af0418f..11a333b161bc 100644
--- a/stoc/source/security/lru_cache.h
+++ b/stoc/source/security/lru_cache.h
@@ -95,7 +95,7 @@ inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::setSize(
{
m_key2element.clear();
delete [] m_block;
- m_block = 0;
+ m_block = NULL;
m_size = size;
if (0 < m_size)
diff --git a/store/source/storbase.hxx b/store/source/storbase.hxx
index 1924a69440da..05bc66e6581e 100644
--- a/store/source/storbase.hxx
+++ b/store/source/storbase.hxx
@@ -688,26 +688,26 @@ public:
T * operator->()
{
T * pImpl = dynamic_page_cast<T>(m_xPage.get());
- OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
+ OSL_PRECOND(pImpl != nullptr, "store::PageHolder<T>::operator*(): Null pointer");
return pImpl;
}
T const * operator->() const
{
T const * pImpl = dynamic_page_cast<T>(m_xPage.get());
- OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
+ OSL_PRECOND(pImpl != nullptr, "store::PageHolder<T>::operator*(): Null pointer");
return pImpl;
}
T & operator*()
{
T * pImpl = dynamic_page_cast<T>(m_xPage.get());
- OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
+ OSL_PRECOND(pImpl != nullptr, "store::PageHolder<T>::operator*(): Null pointer");
return (*pImpl);
}
T const & operator*() const
{
T const * pImpl = dynamic_page_cast<T>(m_xPage.get());
- OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
+ OSL_PRECOND(pImpl != nullptr, "store::PageHolder<T>::operator*(): Null pointer");
return (*pImpl);
}
@@ -719,7 +719,7 @@ public:
pHead->guard(nAddr);
T * pImpl = dynamic_page_cast<T>(pHead);
- OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::guard(): Null pointer");
+ OSL_PRECOND(pImpl != nullptr, "store::PageHolder<T>::guard(): Null pointer");
pImpl->guard();
return store_E_None;
diff --git a/sw/source/filter/ww8/writerwordglue.cxx b/sw/source/filter/ww8/writerwordglue.cxx
index 25ad1a18e046..d42389f93633 100644
--- a/sw/source/filter/ww8/writerwordglue.cxx
+++ b/sw/source/filter/ww8/writerwordglue.cxx
@@ -256,14 +256,14 @@ namespace myImplHelpers
//If we've used it once, don't reuse it
if (pRet && (maUsedStyles.end() != maUsedStyles.find(pRet)))
- pRet = 0;
+ pRet = nullptr;
if (!pRet)
{
pRet = maHelper.GetStyle(rName);
//If we've used it once, don't reuse it
if (pRet && (maUsedStyles.end() != maUsedStyles.find(pRet)))
- pRet = 0;
+ pRet = nullptr;
}
bool bStyExist = pRet != nullptr;