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: 2011-02-01 19:33:55
#5146: Assertion fails in visitation_impl.hpp with nested variants
------------------------------------------------------+---------------------
Reporter: Florian Goujeon <flo.goujeon@â¦> | Owner: ebf
Type: Bugs | Status: new
Milestone: To Be Determined | Component: variant
Version: Boost 1.45.0 | Severity: Problem
Resolution: | Keywords: variant assert assertion nested
------------------------------------------------------+---------------------
Comment (by Florian Goujeon <flo.goujeon@â¦>):
OK, I got it.
Since ptr_to_ptr_to_tv1 kinda contains direct_ptr_to_ptr_to_tv1, variant
has to destruct direct_ptr_to_ptr_to_tv1 AFTER
direct_ptr_to_ptr_to_tv1.pointed_test_variant() was copied into
ptr_to_ptr_to_tv1.
Currently, I guess variant clears its content (i.e. calls the destructor
of its contained object) then sets it with a copy of the new object. This
is the most natural behavior, but it causes problems when the copy
constructor of the new object needs data that are stored in the previously
contained object.
I don't know the code of Boost.Variant, so I won't be able to write a
patch.
But basically, the changes I made in my implementation can be summarized
like this:
BEFORE:
{{{
template<typename Clear, typename Set>
void
clear_and_set(const Set& value)
{
(*reinterpret_cast<Clear*>(buffer_)).~Clear(); //clear
new(buffer_) Set(value); //set
}
}}}
AFTER:
{{{
template<typename Clear, typename Set>
void
clear_and_set(const Set& value)
{
char old_buffer[Size];
for(unsigned int i = 0; i < Size; ++i)
{
old_buffer[i] = buffer_[i];
}
new(buffer_) Set(value); //set
(*reinterpret_cast<Clear*>(old_buffer)).~Clear(); //clear
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5146#comment:1> 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:05 UTC