Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5146: Assertion fails in visitation_impl.hpp with nested variants
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-12-10 15:02:54
#5146: Assertion fails in visitation_impl.hpp with nested variants
-------------------------------------+-------------------------------------
Reporter: Florian Goujeon | Owner: ebf
<flo.goujeon@â¦> | Status: new
Type: Bugs | Component: variant
Milestone: To Be Determined | Severity: Problem
Version: Boost 1.45.0 | Keywords: variant assert
Resolution: | assertion nested
-------------------------------------+-------------------------------------
Comment (by apolukhin):
This looks more like a `ptr_to_test_variant` issue, not variant's one.
Take a look at this code:
{{{
const ptr_to_test_variant& direct_ptr_to_ptr_to_tv1 =
get<ptr_to_test_variant>(ptr_to_ptr_to_tv1);
ptr_to_ptr_to_tv1 = direct_ptr_to_ptr_to_tv1.pointed_test_variant();
}}}
You've got the chain: {{{ ptr_to_ptr_to_tv1 -> direct_ptr_to_ptr_to_tv1 ->
unnamed }}}
Then you try to do the following: {{{ ptr_to_ptr_to_tv1 = unnamed; }}}
Before assigning anything to `ptr_to_ptr_to_tv1` it will delete the data
it owns:
{{{
delete direct_ptr_to_ptr_to_tv1;
delete unnamed;
}}}
And only after that will attempt to do the assignment, but `delete
unnamed` is already called.
Much better solution would be to modify code of `ptr_to_test_variant`,
(you do know that loops are possible, so make small trick to workaround
such cases):
{{{
ptr_to_test_variant&
ptr_to_test_variant::operator=(const ptr_to_test_variant& rhs)
{
test_variant* tmp_ptr = pointed_test_variant_;
pointed_test_variant_ = new test_variant(*rhs.pointed_test_variant_);
// Even if there was a loop, data is copied and new
pointed_test_variant_
// does not depends on old data at all. We are free to delete the old
data.
delete tmp_ptr;
return *this;
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5146#comment:3> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC