Potential scoped_ptr improvement

The incantation scoped_ptr<Base> x( new Derived ); will succeed and produce undefined behavior upon x's destruction unless Derived has a trivial or virtual d'tor. It would be pretty easy to prevent something like that from compiling when has_virtual_destructor<Base>::value is false. Thoughts? -- Dave Abrahams BoostPro Computing http://www.boostpro.com

AMDG On 9/29/2010 6:01 PM, David Abrahams wrote:
The incantation
scoped_ptr<Base> x( new Derived );
will succeed and produce undefined behavior upon x's destruction unless Derived has a trivial or virtual d'tor.
It would be pretty easy to prevent something like that from compiling when has_virtual_destructor<Base>::value is false. Thoughts?
You just need to be careful only to use has_virtual_destructor when there's compiler support, since the implementation falls back on always returning false. In Christ, Steven Watanabe

On Wed, Sep 29, 2010 at 9:53 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
On 9/29/2010 6:01 PM, David Abrahams wrote:
The incantation
scoped_ptr<Base> x( new Derived );
will succeed and produce undefined behavior upon x's destruction unless Derived has a trivial or virtual d'tor.
It would be pretty easy to prevent something like that from compiling when has_virtual_destructor<Base>::value is false. Thoughts?
You just need to be careful only to use has_virtual_destructor when there's compiler support, since the implementation falls back on always returning false.
If there's no support, we should fall back to using is_polymorphic. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (3)
-
Dave Abrahams
-
David Abrahams
-
Steven Watanabe