|
Boost : |
From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2005-12-30 10:20:10
Joe Gottman wrote:
> There is an error in the implementation of the converting assignment
> operator for optional<T>. It is currently implemented as
>
> template<class U>
> optional& operator= ( optional<U> const& rhs )
> {
> this->assign(rhs.get());
> return *this ;
> }
>
> The problem with this is that if rhs is not initialized then rhs.get()
> asserts. This function should be rewritten as
>
> template<class U>
> optional& operator= ( optional<U> const& rhs )
> {
> if (rhs.is_initialized())
> this->assign(rhs.get());
> else
> destroy();
> return *this ;
> }
>
Yikes!
Of course...
The fix is not as simple as that (because destroy() invokes UB if '*this' is
absent), but, ya, that's the idea.
Thank for reporting it!
Fernando Cacciola
SciSoft
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk