Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2001-01-06 11:02:51

David Abrahams wrote on 1/6/2001 10:38 AM

>I think this is a mistake. Conversions to/from auto_ptr_ref<X> allow us to
>convert between auto_ptr<X> to auto_ptr<X[]>, which will call the wrong
>version of delete. I think you need to use a new class, e.g.
>auto_ptr_array_ref, to do this. And since you aren't depending on details of
>auto_ptr_ref any more, it should work portably.

Excellent eye Dave!

Unfortunately your suggested fix does not solve the problem. Even with
auto_ptr_array_ref the member template copy constructor and member
template conversion operators of the primary template allow conversions
both ways:

        template<class Y> auto_ptr(auto_ptr<Y>& a) throw();
        template<class Y> operator auto_ptr<Y>() throw();

However, adding the following to the primary template's private section
seems to do the trick:

template<class X>
class auto_ptr
        X* ptr_;

        template<class Y> auto_ptr(auto_ptr<Y[]>&) throw();
        template<class Y> operator auto_ptr<Y[]>() throw();

This even works with the specialization using auto_ptr_ref as originally
proposed. I'm not positive I fully understand the reasons.

There may be other/better ways of shorting out this unwanted conversion.

This issue definitely needs closer study.


Boost list run by bdawes at, gregod at, cpdaniel at, john at