[smart_ptr] enable_shared_from_this / sp_accept_owner / virtual dtor

In case someone is interested: The attached enable_shared_from_this proves that it is possible to add sp_accept_owner without forcing a virtual dtor. It's compatible with the 1.35.0 features and overhead. Regards, Daniel

On Sun, 2008-05-04 at 11:59 +0200, Daniel Frey wrote:
In case someone is interested: The attached enable_shared_from_this proves that it is possible to add sp_accept_owner without forcing a virtual dtor. It's compatible with the 1.35.0 features and overhead.
Oops, it lacked an ADL protector (see the corrected version attached). This shows that the current regression tests do not catch this problem (it was triggered by libs/signals/src/connection.cpp for example). Which raises the question whether or not the specification should allow an ADL protector. Personally, I would like to see that, even that it's required. Opinions? Regards, Daniel

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sunday 04 May 2008 09:09 am, Daniel Frey wrote:
Oops, it lacked an ADL protector (see the corrected version attached). This shows that the current regression tests do not catch this problem (it was triggered by libs/signals/src/connection.cpp for example). Which raises the question whether or not the specification should allow an ADL protector. Personally, I would like to see that, even that it's required. Opinions?
What is an ADL protector? I'm not familiar with that idea. I see you added a namespace and a using statement, but what problem does it solve? - -- Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIHyQ25vihyNWuA4URArZJAKCFGFYq51FhqNmFutKotNG1pv8SNwCeOMx0 OJHBlU8azHXaPBD7aMWSy1s= =sPGN -----END PGP SIGNATURE-----

On Mon, 2008-05-05 at 11:13 -0400, Frank Mori Hess wrote:
What is an ADL protector? I'm not familiar with that idea. I see you added a namespace and a using statement, but what problem does it solve?
Generally, an ADL protector prevents derivation from boost::enable_shared_from_this to bring in all other functions from namespace boost. Example (try it with boost 1.35.0): #include <boost/enable_shared_from_this.hpp> #include <boost/utility.hpp> namespace A { struct X : boost::enable_shared_from_this< X > {}; template< typename T > void next( const T& ) {} } template< typename T > void prior( const T& ) {} int main() { A::X x; next( x ); prior( x ); } That is the reason why it might be a good idea to allow/require an ADL protector for enable_shared_from_this. In the example implementation I showed it also solves another problem: sp_accept_owner is called with a boost::shared_ptr as the first argument. Given that you have a class X which is *not* derived from enable_shared_from_this, it would pick up enable_shared_from_this' sp_accept_owner if it's not protected by an ADL barrier (another common name for ADL protector), since it's signature is a better match than the default sp_accept_owner(...). By adding the ADL protector, the sp_accept_owner inside the protector is only considered if the pointer passed as the second argument has an accessible base class from the same namespace (enable_shared_from_this_impl) - which can only be enable_shared_from_this<U>. Regards, Daniel
participants (2)
-
Daniel Frey
-
Frank Mori Hess