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

More loplugin:nullptr automatic rewrite (within templates)

Change-Id: I9bc06cfb5eeb38fd7ae7fb25f876ea9f96e4a65a
üst 46fe3bdd
......@@ -200,7 +200,7 @@ namespace basegfx
if(!bNecessary)
{
delete mpLine;
mpLine = 0L;
mpLine = nullptr;
}
}
}
......
......@@ -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;
......
......@@ -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/");
......
......@@ -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);
}
......
......@@ -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 >
......
......@@ -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);
}
......
......@@ -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
......
......@@ -128,7 +128,7 @@ class SingletonRef
if (m_nRef == 0)
{
delete m_pInstance;
m_pInstance = 0;
m_pInstance = NULL;
}
// <- GLOBAL SAFE
}
......
......@@ -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 ) );
}
......
......@@ -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; }
};
......
......@@ -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;
}
}
......
......@@ -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;
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
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