Re: [Boost-bugs] [Boost C++ Libraries] #3604: Access violation on diamond inheritance

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3604: Access violation on diamond inheritance
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-12-01 12:54:06


#3604: Access violation on diamond inheritance
----------------------------------+-----------------------------------------
  Reporter: kondo@… | Owner: ramey
      Type: Support Requests | Status: closed
 Milestone: Boost 1.41.0 | Component: serialization
   Version: Boost 1.40.0 | Severity: Not Applicable
Resolution: invalid | Keywords:
----------------------------------+-----------------------------------------

Comment(by kondo@…):

 It may be out of C++ standard topic.
 The static down cast via virtual base class is illegal.
 But I think that using void pointer, the most of compiler works correctly.
 And it is one of the essence of void-cast mechanism.
 See next exmample.
 {{{
         Target* pTarget = new Target;
         Sub1* pSub1 = new Sub1;
         VBase *pVbTarget = pTarget;
         VBase *pVbSub1 = pSub1;
         std::ptrdiff_t dTargetToVBase =
             static_cast<unsigned char *>(static_cast<void *>(pTarget)) -
             static_cast<unsigned char *>(static_cast<void *>(pVbTarget));
         std::ptrdiff_t dSub12VBase =
             static_cast<unsigned char *>(static_cast<void *>(pSub1)) -
             static_cast<unsigned char *>(static_cast<void *>(pVbSub1));
         Target *pTarget_2 = static_cast<Target *>(static_cast<void *>(
             static_cast<unsigned char *>(static_cast<void *>(pVbTarget)) +
 dTargetToVBase));
         Sub1 *pSub1_2 = static_cast<Sub1 *>(static_cast<void *>(
             static_cast<unsigned char *>(static_cast<void *>(pVbSub1)) +
 dSub12VBase));
 }}}

 My understanding of serialization library is not perfect.

 But I think that there is a possibility that serialize via virtual base
 class.

 Please hear me.

 I found a part of code that seems to support void downcast via virtual
 base class.

 void_caster_shortcut::vbc_downcas is it.

 https://svn.boost.org/trac/boost/browser/trunk/libs/serialization/src/void_cast.cpp#L126

 This function is called from void_caster_shortcut::downcast.

 https://svn.boost.org/trac/boost/browser/trunk/libs/serialization/src/void_cast.cpp#L95

 In function void_caster_shortcut::downcast, the data member
 m_includes_virtual_base is very important.

 https://svn.boost.org/trac/boost/browser/trunk/libs/serialization/src/void_cast.cpp#L90

 My code (main.cpp) failure case,
 {{{
 94 virtual void const *
 95 downcast(void const * const t) const{
 96 if(m_includes_virtual_base) // false
 97 return vbc_downcast(t);
 98 => return static_cast<const char *> ( t ) + m_difference;
 99 }
 }}}

 success case,
 {{{
 94 virtual void const *
 95 downcast(void const * const t) const{
 96 if(m_includes_virtual_base) // true
 97 => return vbc_downcast(t);
 98 return static_cast<const char *> ( t ) + m_difference;
 99 }
 }}}

 In failure case,
 I think that the data member m_includes_virtual_base is set to false in
 spite of the virtual inheritance.

 I modified the library code to always call vbc_downcast.
 Of course it's temporary.
 {{{
 94 virtual void const *
 95 downcast(void const * const t) const{
 96 if(true) // temporary always true
 97 => return vbc_downcast(t);
 98 return static_cast<const char *> ( t ) + m_difference;
 99 }
 }}}

 Both EXPORT sequences work correctly.

 The data member m_includes_virtual_base is set in void_caster_shortcut's
 constructor,
 And it is called in void_caster::recursive_register.
 (Return to my analysis.)

 I think it may be possible to modify m_includes_virtual_base registration
 algorithm.

 Am I missing any big problems?

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3604#comment:7>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC