[Libreoffice-commits] core.git: embedserv/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 8 14:40:27 UTC 2019


 embedserv/source/inprocserv/inprocembobj.cxx |   22 +++++++++++-----------
 embedserv/source/inprocserv/smartpointer.hxx |    9 +++++++--
 2 files changed, 18 insertions(+), 13 deletions(-)

New commits:
commit 48ab06d962e584091f8e2771bc9863ed886fa39f
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Fri Nov 8 10:26:51 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Nov 8 15:39:15 2019 +0100

    Avoid C++20 comparison operator overloading ambiguities (clang-cl -std=c++2a)
    
    The main problem was the non-explicit inprocserv::ComSmart<T>::operator T*()
    that caused ambiguities between inprocserv::ComSmart<T>::operator ==(const T*)
    and the built-in operator == taking two (cv-qualified) T*.
    
    Many uses of that non-explicit conversion operator could be covered by an
    explicit bool conversion operator, but some needed the introduction of a get()
    function.
    
    Also, one of the operator == was used by the C++20 overload resolution in a way
    that it now needs to return bool.  (And the other functions returning BOOL could
    be cleaned up, too.)
    
    Change-Id: I8065f0955a60207c2bd6d8e583d13bc15f324f38
    Reviewed-on: https://gerrit.libreoffice.org/82273
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/embedserv/source/inprocserv/inprocembobj.cxx b/embedserv/source/inprocserv/inprocembobj.cxx
index ec33e7474070..23a1df21a579 100644
--- a/embedserv/source/inprocserv/inprocembobj.cxx
+++ b/embedserv/source/inprocserv/inprocembobj.cxx
@@ -157,7 +157,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
 
                 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
                 if ( SUCCEEDED( hr ) && pPersist && m_pStorage )
-                    hr = pPersist->InitNew( m_pStorage );
+                    hr = pPersist->InitNew( m_pStorage.get() );
             }
             else if ( m_nInitMode == LOAD_FROM_STORAGE )
             {
@@ -166,7 +166,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
 
                 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
                 if ( SUCCEEDED( hr ) && pPersist && m_pStorage )
-                    hr = pPersist->Load( m_pStorage );
+                    hr = pPersist->Load( m_pStorage.get() );
             }
             else if ( m_nInitMode == LOAD_FROM_FILE )
             {
@@ -192,13 +192,13 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
         if ( SUCCEEDED( hr ) && pOleObject )
         {
             if ( m_pClientSite )
-                pOleObject->SetClientSite( m_pClientSite );
+                pOleObject->SetClientSite( m_pClientSite.get() );
 
             for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
                 if ( m_pOleAdvises[nInd] )
                 {
                     DWORD nRegID = 0;
-                    if ( SUCCEEDED( pOleObject->Advise( m_pOleAdvises[nInd], &nRegID ) ) && nRegID > 0 )
+                    if ( SUCCEEDED( pOleObject->Advise( m_pOleAdvises[nInd].get(), &nRegID ) ) && nRegID > 0 )
                         m_pOleAdvises[nInd]->SetRegID( nRegID );
                 }
         }
@@ -211,7 +211,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
                 if ( m_pDataAdvises[nInd] )
                 {
                     DWORD nRegID = 0;
-                    if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd], &nRegID ) ) && nRegID > 0 )
+                    if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd].get(), &nRegID ) ) && nRegID > 0 )
                         m_pDataAdvises[nInd]->SetRegID( nRegID );
                 }
         }
@@ -221,7 +221,7 @@ BOOL InprocEmbedDocument_Impl::CheckDefHandler()
         if ( SUCCEEDED( hr ) && pIViewObject )
         {
             if ( m_pViewAdvise )
-                pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise );
+                pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise.get() );
         }
     }
 
@@ -659,7 +659,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetCurFile( LPOLESTR
 
 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )
 {
-    if ( pSite == m_pClientSite )
+    if ( pSite == m_pClientSite.get() )
         return S_OK;
 
     if ( !pSite )
@@ -988,7 +988,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink
             ComSmart<OleWrapperAdviseSink> pOwnAdvise(new OleWrapperAdviseSink(aListener));
             DWORD nRegID = 0;
 
-            if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise, &nRegID ) ) && nRegID > 0 )
+            if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise.get(), &nRegID ) ) && nRegID > 0 )
             {
                 pOwnAdvise->SetRegID( nRegID );
                 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pOleAdvises );
@@ -1191,7 +1191,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC *
             ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( ComSmart<IAdviseSink>( pAdvSink ), pFormatetc, advf ) );
             DWORD nRegID = 0;
 
-            if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise, &nRegID ) ) && nRegID > 0 )
+            if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise.get(), &nRegID ) ) && nRegID > 0 )
             {
                 pOwnAdvise->SetRegID( nRegID );
                 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pDataAdvises );
@@ -1417,7 +1417,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD asp
             ComSmart<IAdviseSink> aListener(pAdvSink);
             ComSmart<OleWrapperAdviseSink> pOwnAdvise(new OleWrapperAdviseSink(aListener, aspects, advf));
 
-            if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise ) ) )
+            if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise.get() ) ) )
             {
                 m_pViewAdvise = pOwnAdvise;
                 return S_OK;
@@ -1442,7 +1442,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetAdvise( DWORD *pA
         if ( pAdvf )
             *pAdvf = m_pViewAdvise->GetViewAdviseFlag();
 
-        *ppAdvSink = m_pViewAdvise->GetOrigAdvise();
+        *ppAdvSink = m_pViewAdvise->GetOrigAdvise().get();
         if ( *ppAdvSink )
             (*ppAdvSink)->AddRef();
     }
diff --git a/embedserv/source/inprocserv/smartpointer.hxx b/embedserv/source/inprocserv/smartpointer.hxx
index 38750e79ae6d..5e1606cad725 100644
--- a/embedserv/source/inprocserv/smartpointer.hxx
+++ b/embedserv/source/inprocserv/smartpointer.hxx
@@ -89,7 +89,12 @@ public:
         return *this;
     }
 
-    operator T*() const
+    explicit operator bool() const
+    {
+        return m_pInterface != nullptr;
+    }
+
+    T* get() const
     {
         return m_pInterface;
     }
@@ -123,7 +128,7 @@ public:
         return ( m_pInterface != rObj.m_pInterface );
     }
 
-    BOOL operator==( const T* pInterface ) const
+    bool operator==( const T* pInterface ) const
     {
         return ( m_pInterface == pInterface );
     }


More information about the Libreoffice-commits mailing list