Fixing bug in exception_ptr cloning of error_info objects.

This commit is contained in:
Emil Dotchevski
2017-03-15 11:39:42 -07:00
parent 10550b69d4
commit 991d600f01
3 changed files with 44 additions and 3 deletions

View File

@ -29,8 +29,7 @@ boost
public:
virtual std::string name_value_string() const = 0;
protected:
virtual error_info_base * clone() const = 0;
virtual
~error_info_base() throw()
@ -44,6 +43,11 @@ boost
error_info:
public exception_detail::error_info_base
{
error_info_base *
clone() const
{
return new error_info<Tag,T>(*this);
}
public:
typedef T value_type;
error_info( value_type const & v ):

View File

@ -142,7 +142,11 @@ boost
refcount_ptr<error_info_container> p;
error_info_container_impl * c=new error_info_container_impl;
p.adopt(c);
c->info_ = info_;
for( error_info_map::const_iterator i=info_.begin(),e=info_.end(); i!=e; ++i )
{
shared_ptr<error_info_base> cp(i->second->clone());
c->info_.insert(std::make_pair(i->first,cp));
}
return p;
}
};

View File

@ -121,9 +121,42 @@ check( boost::shared_ptr<thread_handle> const & t )
}
}
void
test_deep_copy()
{
int const * p1=0;
boost::exception_ptr p;
try
{
BOOST_THROW_EXCEPTION(exc() << answer(42));
BOOST_ERROR("BOOST_THROW_EXCEPTION didn't throw");
}
catch(
exc & e )
{
p1=boost::get_error_info<answer>(e);
p=boost::current_exception();
}
BOOST_TEST(p1!=0);
BOOST_TEST(p);
try
{
boost::rethrow_exception(p);
BOOST_ERROR("rethrow_exception didn't throw");
}
catch(
exc & e )
{
int const * p2=boost::get_error_info<answer>(e);
BOOST_TEST(p2!=0 && *p2==42);
BOOST_TEST(p2!=p1);
}
}
int
main()
{
test_deep_copy();
BOOST_TEST(++exc_count==1);
try
{