mirror of
https://github.com/boostorg/function.git
synced 2025-07-13 12:46:34 +02:00
When copying boost::ref, copy even when the referenced function is empty. Fixes #2642
Patch by Steven Watanabe [SVN r54616]
This commit is contained in:
@ -625,14 +625,10 @@ namespace boost {
|
|||||||
assign_to(const reference_wrapper<FunctionObj>& f,
|
assign_to(const reference_wrapper<FunctionObj>& f,
|
||||||
function_buffer& functor, function_obj_ref_tag)
|
function_buffer& functor, function_obj_ref_tag)
|
||||||
{
|
{
|
||||||
if (!boost::detail::function::has_empty_target(f.get_pointer())) {
|
functor.obj_ref.obj_ptr = (void *)f.get_pointer();
|
||||||
functor.obj_ref.obj_ptr = (void *)f.get_pointer();
|
functor.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
|
||||||
functor.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
|
functor.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
|
||||||
functor.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
|
return true;
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
template<typename FunctionObj,typename Allocator>
|
template<typename FunctionObj,typename Allocator>
|
||||||
bool
|
bool
|
||||||
|
@ -629,6 +629,30 @@ test_ref()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dummy() {}
|
||||||
|
|
||||||
|
static void test_empty_ref()
|
||||||
|
{
|
||||||
|
boost::function<void()> f1;
|
||||||
|
boost::function<void()> f2(boost::ref(f1));
|
||||||
|
|
||||||
|
try {
|
||||||
|
f2();
|
||||||
|
BOOST_ERROR("Exception didn't throw for reference to empty function.");
|
||||||
|
}
|
||||||
|
catch(runtime_error e) {}
|
||||||
|
|
||||||
|
f1 = dummy;
|
||||||
|
|
||||||
|
try {
|
||||||
|
f2();
|
||||||
|
}
|
||||||
|
catch(runtime_error e) {
|
||||||
|
BOOST_ERROR("Error calling referenced function.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void test_exception()
|
static void test_exception()
|
||||||
{
|
{
|
||||||
boost::function<int (int, int)> f;
|
boost::function<int (int, int)> f;
|
||||||
@ -674,6 +698,7 @@ int test_main(int, char* [])
|
|||||||
test_emptiness();
|
test_emptiness();
|
||||||
test_member_functions();
|
test_member_functions();
|
||||||
test_ref();
|
test_ref();
|
||||||
|
test_empty_ref();
|
||||||
test_exception();
|
test_exception();
|
||||||
test_implicit();
|
test_implicit();
|
||||||
test_call();
|
test_call();
|
||||||
|
Reference in New Issue
Block a user