Boost logo

Boost :

Subject: Re: [boost] cannot pass objects of non-POD type ‘class boost::detail::shared_count’ through ‘...’; call will abort at runtime
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-09-17 08:58:23


Dave Steffen wrote:
> Hi Folks
>
> [ Sorry if this gets posted twice; my company email server changed my
> email address, and I think my first post got bounced. Argh.]
>
> Just tried to compile my project with GCC 4.3 and Boost 1.40. (It
> compiles and works just fine with Boost 1.38.)
>
> As part of a home-built thread-locking shared pointer thing, we have
> this code:
>
> /// Constructor from pointer to complete type
> template<class Y>
> explicit shared_locking_ptr( Y * p ): px( p ), pn( p ) // Y must be
> complete
> {
> boost::detail::sp_enable_shared_from_this( pn, p, p );
> }
>
> which now produces this result:
>
> ../util/thread/shared_locking_ptr.hpp:57:9: warning: cannot pass
> objects of non-POD type ‘class boost::detail::shared_count’ through
> ‘...’; call will abort at runtime
>
> In Boost 1.38, the relevent code in shared_ptr.hpp was this AFAICT:
> #ifdef _MANAGED
> [ ... ]
> #else // _MANAGED
> [...]
>
> inline void sp_enable_shared_from_this( shared_count const &
> /*pn*/, ... ) {
> }
>
> #endif // _MANAGED
>
> In 1.40, it's been changed to
>
>
> #ifdef _MANAGED
> [...]
> #else // _MANAGED
>
> inline void sp_enable_shared_from_this( ... )
> {
> }
>
> #endif // _MANAGED
>
>
> Does anyone know why the change?

The signature of sp_enable_shared_from_this has changed, it now takes a
pointer to a shared_ptr as its first argument. Look at the current
shared_ptr constructor:

    template<class Y>
    explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
    {
        boost::detail::sp_enable_shared_from_this( this, p, p );
    }

Relying on implementation details has its maintenance costs. :-) You'll
probably need to refactor shared_locking_ptr to contain (or privately derive
from) a shared_ptr.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk