Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54616 - in trunk: boost/function libs/function/test
From: daniel_james_at_[hidden]
Date: 2009-07-03 18:20:26


Author: danieljames
Date: 2009-07-03 18:20:26 EDT (Fri, 03 Jul 2009)
New Revision: 54616
URL: http://svn.boost.org/trac/boost/changeset/54616

Log:
When copying boost::ref, copy even when the referenced function is empty. Fixes #2642

Patch by Steven Watanabe
Text files modified:
   trunk/boost/function/function_template.hpp | 12 ++++--------
   trunk/libs/function/test/function_test.cpp | 25 +++++++++++++++++++++++++
   2 files changed, 29 insertions(+), 8 deletions(-)

Modified: trunk/boost/function/function_template.hpp
==============================================================================
--- trunk/boost/function/function_template.hpp (original)
+++ trunk/boost/function/function_template.hpp 2009-07-03 18:20:26 EDT (Fri, 03 Jul 2009)
@@ -625,14 +625,10 @@
         assign_to(const reference_wrapper<FunctionObj>& f,
                   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.is_const_qualified = is_const<FunctionObj>::value;
- functor.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
- return true;
- } else {
- return false;
- }
+ functor.obj_ref.obj_ptr = (void *)f.get_pointer();
+ functor.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
+ functor.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
+ return true;
         }
         template<typename FunctionObj,typename Allocator>
         bool

Modified: trunk/libs/function/test/function_test.cpp
==============================================================================
--- trunk/libs/function/test/function_test.cpp (original)
+++ trunk/libs/function/test/function_test.cpp 2009-07-03 18:20:26 EDT (Fri, 03 Jul 2009)
@@ -629,6 +629,30 @@
   }
 }
 
+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()
 {
   boost::function<int (int, int)> f;
@@ -674,6 +698,7 @@
   test_emptiness();
   test_member_functions();
   test_ref();
+ test_empty_ref();
   test_exception();
   test_implicit();
   test_call();


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk