[Libreoffice-commits] core.git: basegfx/source bridges/source compilerplugins/clang include/com include/rtl include/salhelper include/sfx2 include/tools sal/rtl stoc/source store/source sw/source

Stephan Bergmann sbergman at redhat.com
Thu Dec 10 08:34:56 PST 2015


 basegfx/source/inc/hommatrixtemplate.hxx       |    2 
 bridges/source/cpp_uno/shared/guardedarray.hxx |    2 
 compilerplugins/clang/store/nullptr.cxx        |   68 +++++++++++++++++++++++++
 include/com/sun/star/uno/Reference.h           |    2 
 include/com/sun/star/uno/Reference.hxx         |    8 +-
 include/rtl/ref.hxx                            |    8 +-
 include/salhelper/dynload.hxx                  |    2 
 include/salhelper/singletonref.hxx             |    2 
 include/sfx2/itemconnect.hxx                   |    2 
 include/tools/ref.hxx                          |   20 +++----
 include/tools/weakbase.hxx                     |    4 -
 sal/rtl/math.cxx                               |    4 -
 stoc/source/security/lru_cache.h               |    2 
 store/source/storbase.hxx                      |   10 +--
 sw/source/filter/ww8/writerwordglue.cxx        |    4 -
 15 files changed, 104 insertions(+), 36 deletions(-)

New commits:
commit 4a1edf626ad48b5955892e5590d75fa7ae5eaf58
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Dec 10 17:33:54 2015 +0100

    More loplugin:nullptr automatic rewrite (within templates)
    
    Change-Id: I9bc06cfb5eeb38fd7ae7fb25f876ea9f96e4a65a

diff --git a/basegfx/source/inc/hommatrixtemplate.hxx b/basegfx/source/inc/hommatrixtemplate.hxx
index 58a3b46..76dc8a5 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 ad5d6bd..13e6f16 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 8bed1ce..6bf4e54 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 8e266cd..368c998 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 b25083d..f7a7131 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 3ffcfc0..ea219cd 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 91d70c1..b5b16fa 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 84064be..52e54a5 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 c0cf7a6..ae265b7 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 9cd1bf5..2ca5def 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 652ea45..4087160 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 fd33130..be8ebbe 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 51459af..11a333b 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 1924a69..05bc66e 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 25ad1a1..d42389f 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;


More information about the Libreoffice-commits mailing list