diff -uNr libsigc++-2.0.11-cvs/ChangeLog libsigc++-2.0.11/ChangeLog
--- libsigc++-2.0.11-cvs/ChangeLog	2005-04-30 18:53:32.000000000 -0700
+++ libsigc++-2.0.11/ChangeLog	2005-05-07 00:38:37.000000000 -0700
@@ -1,3 +1,46 @@
+2005-05-06  Régis Duchesne <hpreg@vmware.com>
+
+	* sigc++/macros/limit_reference.h.m4 (added):
+	* sigc++/Makefile.am:
+	New class that just stores a reference, and makes sure that if the
+	reference derives from trackable, then the trackable reference will be
+	used instead of the derived reference in visit_each().
+	* sigc++/functors/macros/mem_fun.h.m4: Better fix for bug #169225 by
+	Régis Duchesne and Christian Hammond, based on the new limit_reference
+	class.
+	* sigc++/adaptors/bound_argument.h (added): New class (built upon the
+	new limit_reference class) that handles all 3 kinds of bound arguments:
+	by value, by reference, and by constant reference. References are
+	unwrapped in the bound_argument's constructor.
+	* sigc++/adaptors/macros/bind.h.m4: Fix for bug #302327 by Régis
+	Duchesne. Bound arguments now need to know whether they are passed by
+	reference or not. So bind() now builds bind_functor instances using
+	'reference_wrapper<Foo>' types, instead of 'Foo &' types. The
+	bind_functor code is modified to compensate.
+	* sigc++/adaptors/macros/bind_return.h.m4: Similar fix for a similar
+	bug (unfiled) with bound return arguments.
+	* sigc++/reference_wrapper.h:
+	* sigc++/type_traits.h:
+	The reference_wrapper class is only used in bound_argument.h. Put
+	correct but unused code under #if 0.
+	* sigc++/adaptors/lambda/base.h: This file needs reference_wrapper.h,
+	but was incorrectly relying on type_traits.h to include it.
+	* tests/Makefile.am:
+	* tests/test_virtualbase_delete.cc (deleted):
+	* tests/test_virtualbase_delete_ref_param.cc (deleted):
+	* tests/test_limit_reference.cc (added):
+	Replaced test_virtualbase_delete*.cc with a simpler
+	test_limit_reference.cc which checks for all 3 aspects of the same bug
+	in one file.
+	* tests/test_bind_ref.cc: Slots must use 'Foo &' types. We were lucky
+	this broken usage worked before this change. The change in
+	type_traits.h made this bug obvious, by preventing the code to compile.
+	* tests/test_bind_return.cc: After my change, bind() and bind_return()
+	must use 'reference_wrapper<Foo>' types.
+	* tests/test_custom.cc: Made this test a no-op (so it does not perturb
+	'make check' on released versions of the library) and made it a
+	template ready to be modified by hackers.
+
 2005-05-01  Murray Cumming <murrayc@murrayc.com>
 
 	* sigc++/functors/slot_base.cc: 
diff -uNr libsigc++-2.0.11-cvs/sigc++/adaptors/bound_argument.h libsigc++-2.0.11/sigc++/adaptors/bound_argument.h
--- libsigc++-2.0.11-cvs/sigc++/adaptors/bound_argument.h	1969-12-31 16:00:00.000000000 -0800
+++ libsigc++-2.0.11/sigc++/adaptors/bound_argument.h	2005-05-07 00:38:37.000000000 -0700
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2002, The libsigc++ Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _SIGC_BOUND_ARGUMENT_H_
+#define _SIGC_BOUND_ARGUMENT_H_
+
+
+#include <sigc++/limit_reference.h>
+#include <sigc++/reference_wrapper.h>
+
+
+namespace sigc {
+
+
+/** bound_argument object for a bound argument that is passed by bind() or
+ * returned by bind_return() by value.
+ * - @e T_type The type of the bound argument.
+ */
+template <class T_type>
+class bound_argument
+{
+public:
+  /** Constructor.
+   * @param _A_argument The argument to bind.
+   */
+  bound_argument(const T_type &_A_argument)
+    : visited(_A_argument)
+    {}
+
+  /** Retrieve the entity to visit in visit_each().
+   * @return The bound argument.
+   */
+  inline const T_type &visit() const
+    { return visited; }
+
+  /** Retrieve the entity to pass to the bound functor or return.
+   * @return The bound argument.
+   */
+  inline T_type &invoke()
+    { return visited; }
+
+private:
+  /** The value of the argument.
+   */
+  T_type visited;
+};
+
+/** bound_argument object for a bound argument that is passed by bind() or
+ * returned by bind_return() by reference.
+ * - @e T_wrapped The type of the bound argument.
+ */
+template <class T_wrapped>
+class bound_argument<reference_wrapper<T_wrapped> >
+{
+public:
+  /** Constructor.
+   * @param _A_argument The argument to bind.
+   */
+  bound_argument(const reference_wrapper<T_wrapped> &_A_argument)
+    : visited(unwrap(_A_argument))
+    {}
+
+  /** Retrieve the entity to visit in visit_each().
+   * @return The limited_reference to the bound argument.
+   */
+  inline const limit_reference<T_wrapped> &visit() const
+    { return visited; }
+
+  /** Retrieve the entity to pass to the bound functor or return.
+   * @return The bound argument.
+   */
+  inline T_wrapped &invoke()
+    { return visited.invoke(); }
+
+private:
+  /** The limited_reference to the bound argument.
+   */
+  limit_reference<T_wrapped> visited;
+};
+
+/** bound_argument object for a bound argument that is passed by bind() or
+ * returned by bind_return() by const reference.
+ * - @e T_wrapped The type of the bound argument.
+ */
+template <class T_wrapped>
+class bound_argument<const_reference_wrapper<T_wrapped> >
+{
+public:
+  /** Constructor.
+   * @param _A_argument The argument to bind.
+   */
+  bound_argument(const const_reference_wrapper<T_wrapped> &_A_argument)
+    : visited(unwrap(_A_argument))
+    {}
+
+  /** Retrieve the entity to visit in visit_each().
+   * @return The const_limited_reference to the bound argument.
+   */
+  inline const const_limit_reference<T_wrapped> &visit() const
+    { return visited; }
+
+  /** Retrieve the entity to pass to the bound functor or return.
+   * @return The bound argument.
+   */
+  inline const T_wrapped &invoke()
+    { return visited.invoke(); }
+
+private:
+  /** The const_limited_reference to the bound argument.
+   */
+  const_limit_reference<T_wrapped> visited;
+};
+
+/** Implementation of visit_each() specialized for the bound_argument class.
+ * Call visit_each() on the entity returned by the bound_argument's visit()
+ * method.
+ * - @e T_action The type of functor to invoke.
+ * - @e T_type The type of bound_argument.
+ * @param _A_action The functor to invoke.
+ * @param _A_argument The visited instance.
+ */
+template <class T_action, class T_type>
+void
+visit_each(const T_action &_A_action,
+           const bound_argument<T_type> &_A_argument)
+{
+  visit_each(_A_action, _A_argument.visit());
+}
+
+
+} /* namespace sigc */
+
+
+#endif /* _SIGC_BOUND_ARGUMENT_H_ */
diff -uNr libsigc++-2.0.11-cvs/sigc++/adaptors/lambda/base.h libsigc++-2.0.11/sigc++/adaptors/lambda/base.h
--- libsigc++-2.0.11-cvs/sigc++/adaptors/lambda/base.h	2005-04-28 00:58:11.000000000 -0700
+++ libsigc++-2.0.11/sigc++/adaptors/lambda/base.h	2005-05-07 00:38:37.000000000 -0700
@@ -3,6 +3,7 @@
 #ifndef _SIGC_LAMBDA_BASE_HPP_
 #define _SIGC_LAMBDA_BASE_HPP_
 #include <sigc++/adaptors/adaptor_trait.h>
+#include <sigc++/reference_wrapper.h>
 
 namespace sigc {
 
diff -uNr libsigc++-2.0.11-cvs/sigc++/adaptors/macros/bind.h.m4 libsigc++-2.0.11/sigc++/adaptors/macros/bind.h.m4
--- libsigc++-2.0.11-cvs/sigc++/adaptors/macros/bind.h.m4	2005-04-30 22:37:18.000000000 -0700
+++ libsigc++-2.0.11/sigc++/adaptors/macros/bind.h.m4	2005-05-07 00:38:37.000000000 -0700
@@ -21,7 +21,7 @@
 define([DEDUCE_RESULT_TYPE_COUNT],[dnl
   template <LOOP(class T_arg%1, eval(CALL_SIZE))>
   struct deduce_result_type_internal<LIST($2, LOOP(T_arg%1,eval(CALL_SIZE)))>
-    { typedef typename adaptor_type::template deduce_result_type<LIST(LOOP(_P_(T_arg%1), eval(CALL_SIZE-$2)), LOOP(_P_(T_type%1), $1))>::type type; };
+    { typedef typename adaptor_type::template deduce_result_type<LIST(LOOP(_P_(T_arg%1), eval(CALL_SIZE-$2)), LOOP(_P_(typename unwrap_reference<T_type%1>::type), $1))>::type type; };
 ])
 define([BIND_OPERATOR_LOCATION],[dnl
 ifelse($2,1,,[dnl
@@ -34,16 +34,16 @@
   template <LOOP([class T_arg%1], eval($2-1))>
   typename deduce_result_type<LOOP(T_arg%1,eval($2-1))>::type
   operator()(LOOP(T_arg%1 _A_arg%1,eval($2-1)))
-    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($1-1)), _P_(T_bound),FOR($1,eval($2-1),[_P_(T_arg%1),]))>
-        (LIST(LOOP(_A_arg%1,eval($1-1)), bound_, FOR($1,eval($2-1),[_A_arg%1,])));
+    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($1-1)), _P_(typename unwrap_reference<T_bound>::type), FOR($1,eval($2-1),[_P_(T_arg%1),]))>
+        (LIST(LOOP(_A_arg%1,eval($1-1)), bound_.invoke(), FOR($1,eval($2-1),[_A_arg%1,])));
     }
 
   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
   template <LOOP([class T_arg%1], eval($2-1))>
   typename deduce_result_type<LOOP(T_arg%1,eval($2-1))>::type
   sun_forte_workaround(LOOP(T_arg%1 _A_arg%1,eval($2-1)))
-    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($1-1)), _P_(T_bound),FOR($1,eval($2-1),[_P_(T_arg%1),]))>
-        (LIST(LOOP(_A_arg%1,eval($1-1)), bound_, FOR($1,eval($2-1),[_A_arg%1,])));
+    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($1-1)), _P_(typename unwrap_reference<T_bound>::type), FOR($1,eval($2-1),[_P_(T_arg%1),]))>
+        (LIST(LOOP(_A_arg%1,eval($1-1)), bound_.invoke(), FOR($1,eval($2-1),[_A_arg%1,])));
     }
   #endif
     
@@ -59,16 +59,16 @@
   template <LOOP([class T_arg%1], eval($2-1))>
   typename deduce_result_type<LOOP(T_arg%1,eval($2-1))>::type
   operator()(LOOP(T_arg%1 _A_arg%1, eval($2-1)))
-    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($2-1)), LOOP(_P_(T_type%1), $1))>
-        (LIST(LOOP(_A_arg%1,eval($2-1)), LOOP(bound%1_, $1)));
+    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($2-1)), LOOP(_P_(typename unwrap_reference<T_type%1>::type), $1))>
+        (LIST(LOOP(_A_arg%1,eval($2-1)), LOOP(bound%1_.invoke(), $1)));
     }
 
   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
   template <LOOP([class T_arg%1], eval($2-1))>
   typename deduce_result_type<LOOP(T_arg%1,eval($2-1))>::type
   sun_forte_workaround(LOOP(T_arg%1 _A_arg%1, eval($2-1)))
-    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($2-1)), LOOP(_P_(T_type%1), $1))>
-        (LIST(LOOP(_A_arg%1,eval($2-1)), LOOP(bound%1_, $1)));
+    { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(LOOP([_P_(T_arg%1)],eval($2-1)), LOOP(_P_(typename unwrap_reference<T_type%1>::type), $1))>
+        (LIST(LOOP(_A_arg%1,eval($2-1)), LOOP(bound%1_.invoke(), $1)));
     }
   #endif
     
@@ -87,7 +87,7 @@
 
   template <LOOP(class T_arg%1=void, eval(CALL_SIZE))>
   struct deduce_result_type
-    { typedef typename adaptor_type::template deduce_result_type<LIST(LOOP(_P_(T_arg%1),eval($1)), _P_(T_bound),FOR(eval($1+1),eval(CALL_SIZE-1),[_P_(T_arg%1),]))>::type type; };
+    { typedef typename adaptor_type::template deduce_result_type<LIST(LOOP(_P_(T_arg%1),eval($1)), _P_(typename unwrap_reference<T_bound>::type), FOR(eval($1+1),eval(CALL_SIZE-1),[_P_(T_arg%1),]))>::type type; };
   typedef typename adaptor_type::result_type  result_type;
 
   /** Invokes the wrapped functor passing on the bound argument only.
@@ -97,7 +97,7 @@
   operator()()
   {
     //Note: The AIX compiler sometimes gives linker errors if we do not define this in the class.
-    return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<_P_(T_bound)> (bound_);
+    return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<_P_(typename unwrap_reference<T_bound>::type)> (bound_.invoke());
   }
 
 FOR(eval($1+1),CALL_SIZE,[[BIND_OPERATOR_LOCATION(eval($1+1),%1)]])dnl
@@ -110,7 +110,7 @@
     {}
 
   /// The argument bound to the functor.
-  T_bound bound_;
+  bound_argument<T_bound> bound_;
 };
 
 ])
@@ -129,7 +129,7 @@
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
   template <LIST(int count, LOOP(class T_arg%1, eval(CALL_SIZE)))>
   struct deduce_result_type_internal
-    { typedef typename adaptor_type::template deduce_result_type<LIST(LOOP(_P_(T_arg%1), eval(CALL_SIZE-$1)), LOOP(_P_(T_type%1), $1))>::type type; };
+    { typedef typename adaptor_type::template deduce_result_type<LIST(LOOP(_P_(T_arg%1), eval(CALL_SIZE-$1)), LOOP(_P_(typename unwrap_reference<T_type%1>::type), $1))>::type type; };
 FOR(eval($1+1),eval(CALL_SIZE-1),[[DEDUCE_RESULT_TYPE_COUNT($1,%1)]])dnl
 #endif /*DOXYGEN_SHOULD_SKIP_THIS*/
 
@@ -147,7 +147,7 @@
   operator()()
   {
     //Note: The AIX compiler sometimes gives linker errors if we do not define this in the class.
-    return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_type%1),$1)> (LOOP(bound%1_, $1));
+    return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(typename unwrap_reference<T_type%1>::type), $1)> (LOOP(bound%1_.invoke(), $1));
   }
 
 FOR(2,eval(CALL_SIZE-$1+1),[[BIND_OPERATOR_COUNT($1,%1)]])dnl
@@ -161,7 +161,7 @@
 
   /// The argument bound to the functor.dnl
 FOR(1,$1,[
-  T_type%1 bound%1_;])
+  bound_argument<T_type%1> bound%1_;])
 };
 
 
@@ -196,13 +196,13 @@
 template <LIST(LOOP(class T_type%1, $1), class T_functor)>
 inline bind_functor<-1, T_functor,dnl
 FOR(1,eval($1-1),[
-                    typename unwrap_reference<T_type%1>::type,])
-                    typename unwrap_reference<T_type$1>::type>
+                    T_type%1,])
+                    T_type$1>
 bind(const T_functor& _A_func, LOOP(T_type%1 _A_b%1, $1))
 { return bind_functor<-1, T_functor,dnl
 FOR(1,eval($1-1),[
-                    typename unwrap_reference<T_type%1>::type,])
-                    typename unwrap_reference<T_type$1>::type>
+                    T_type%1,])
+                    T_type$1>
                     (_A_func, LOOP(_A_b%1, $1));
 }
 
@@ -211,6 +211,7 @@
 divert(0)dnl
 __FIREWALL__
 #include <sigc++/adaptors/adaptor_trait.h>
+#include <sigc++/adaptors/bound_argument.h>
 
 namespace sigc { 
 
@@ -366,10 +367,10 @@
  * @ingroup bind
  */
 template <int I_location, class T_bound1, class T_functor>
-inline bind_functor<I_location, T_functor, typename unwrap_reference<T_bound1>::type>
+inline bind_functor<I_location, T_functor, T_bound1>
 bind(const T_functor& _A_func, T_bound1 _A_b1)
 { 
-  return bind_functor<I_location, T_functor, typename unwrap_reference<T_bound1>::type>
+  return bind_functor<I_location, T_functor, T_bound1>
            (_A_func, _A_b1);
 }
 
diff -uNr libsigc++-2.0.11-cvs/sigc++/adaptors/macros/bind_return.h.m4 libsigc++-2.0.11/sigc++/adaptors/macros/bind_return.h.m4
--- libsigc++-2.0.11-cvs/sigc++/adaptors/macros/bind_return.h.m4	2005-02-01 03:02:20.000000000 -0800
+++ libsigc++-2.0.11/sigc++/adaptors/macros/bind_return.h.m4	2005-05-07 00:38:37.000000000 -0700
@@ -25,16 +25,16 @@
    * @return The fixed return value.
    */
   template <LOOP(class T_arg%1, $1)>
-  inline T_return operator()(LOOP(T_arg%1 _A_a%1, $1))
+  inline typename unwrap_reference<T_return>::type operator()(LOOP(T_arg%1 _A_a%1, $1))
     { this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
-        (LOOP(_A_a%1, $1)); return ret_value_;
+        (LOOP(_A_a%1, $1)); return ret_value_.invoke();
     }
 
   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
   template <LOOP(class T_arg%1, $1)>
-  inline T_return sun_forte_workaround(LOOP(T_arg%1 _A_a%1, $1))
+  inline typename unwrap_reference<T_return>::type sun_forte_workaround(LOOP(T_arg%1 _A_a%1, $1))
     { this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
-        (LOOP(_A_a%1, $1)); return ret_value_;
+        (LOOP(_A_a%1, $1)); return ret_value_.invoke();
     }
   #endif
 
@@ -43,6 +43,7 @@
 divert(0)dnl
 __FIREWALL__
 #include <sigc++/adaptors/adaptor_trait.h>
+#include <sigc++/adaptors/bound_argument.h>
 
 namespace sigc {
 
@@ -60,13 +61,13 @@
 {
   template <LOOP(class T_arg%1=void, CALL_SIZE)>
   struct deduce_result_type
-    { typedef T_return type; };
-  typedef T_return result_type;
+    { typedef typename unwrap_reference<T_return>::type type; };
+  typedef typename unwrap_reference<T_return>::type result_type;
 
   /** Invokes the wrapped functor dropping its return value.
    * @return The fixed return value.
    */
-  T_return operator()();
+  typename unwrap_reference<T_return>::type operator()();
 
 FOR(1,CALL_SIZE,[[BIND_RETURN_OPERATOR(%1)]])dnl
 
@@ -79,12 +80,12 @@
     {}
 
   /// The fixed return value.
-  T_return ret_value_; // public, so that visit_each() can access it
+  bound_argument<T_return> ret_value_; // public, so that visit_each() can access it
 };
 
 template <class T_return, class T_functor>
-T_return bind_return_functor<T_return, T_functor>::operator()()
-  { this->functor_(); return ret_value_; }
+typename unwrap_reference<T_return>::type bind_return_functor<T_return, T_functor>::operator()()
+  { this->functor_(); return ret_value_.invoke(); }
 
 
 //template specialization of visit_each<>(action, functor):
@@ -112,8 +113,8 @@
  * @ingroup bind
  */
 template <class T_return, class T_functor>
-inline bind_return_functor<typename unwrap_reference<T_return>::type, T_functor>
+inline bind_return_functor<T_return, T_functor>
 bind_return(const T_functor& _A_functor, T_return _A_ret_value)
-{ return bind_return_functor<typename unwrap_reference<T_return>::type, T_functor>(_A_functor, _A_ret_value); }
+{ return bind_return_functor<T_return, T_functor>(_A_functor, _A_ret_value); }
 
 } /* namespace sigc */
diff -uNr libsigc++-2.0.11-cvs/sigc++/functors/macros/mem_fun.h.m4 libsigc++-2.0.11/sigc++/functors/macros/mem_fun.h.m4
--- libsigc++-2.0.11-cvs/sigc++/functors/macros/mem_fun.h.m4	2005-04-30 17:50:45.000000000 -0700
+++ libsigc++-2.0.11/sigc++/functors/macros/mem_fun.h.m4	2005-05-07 00:38:37.000000000 -0700
@@ -81,49 +81,8 @@
  *
  * @ingroup mem_fun
  */
-template <LIST(class T_return, class T_obj, LOOP(class T_arg%1, $1)), bool I_derives_trackable = is_base_and_derived<sigc::trackable, T_obj>::value>
-class bound_[$2]mem_functor$1
-  : public [$2]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))>
-{
-  typedef [$2]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))> base_type_;
-public:
-  typedef typename base_type_::function_type function_type;
-
-  /** Constructs a bound_[$2]mem_functor$1 object that wraps the passed method.
-   * @param _A_obj Pointer to instance the method will operate on.
-   * @param _A_func Pointer to method will be invoked from operator()().
-   */
-  bound_[$2]mem_functor$1($3 T_obj* _A_obj, function_type _A_func)
-    : base_type_(_A_func),
-    obj_ptr_(_A_obj)
-    {}
-
-  /** Constructs a bound_[$2]mem_functor$1 object that wraps the passed method.
-   * @param _A_obj Reference to instance the method will operate on.
-   * @param _A_func Pointer to method will be invoked from operator()().
-   */
-  bound_[$2]mem_functor$1($3 T_obj& _A_obj, function_type _A_func)
-    : base_type_(_A_func),
-    obj_ptr_(&_A_obj)
-    {}
-
-  /** Execute the wrapped method operating on the stored instance.dnl
-FOR(1, $1,[
-   * @param _A_a%1 Argument to be passed on to the method.])
-   * @return The return value of the method invocation.
-   */
-  T_return operator()(LOOP(typename type_trait<T_arg%1>::take _A_a%1, $1)) const
-    { return (obj_ptr_->*(this->func_ptr_))(LOOP(_A_a%1, $1)); }
-
-//protected:
-  // Pointer to stored object instance.
-  // This is the handler object, such as TheObject in void TheObject::signal_handler().
-  $3 T_obj *obj_ptr_; //This, and its type is used by the visit_each<> specialization below.
-};
-
-//Specialization for T_obj that derives from sigc::trackable.
 template <LIST(class T_return, class T_obj, LOOP(class T_arg%1, $1))>
-class bound_[$2]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1), true)>
+class bound_[$2]mem_functor$1
   : public [$2]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))>
 {
   typedef [$2]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))> base_type_;
@@ -136,7 +95,7 @@
    */
   bound_[$2]mem_functor$1($3 T_obj* _A_obj, function_type _A_func)
     : base_type_(_A_func),
-      obj_ptr_derived_(_A_obj), obj_ptr_(_A_obj)
+      obj_(*_A_obj)
     {}
 
   /** Constructs a bound_[$2]mem_functor$1 object that wraps the passed method.
@@ -145,7 +104,7 @@
    */
   bound_[$2]mem_functor$1($3 T_obj& _A_obj, function_type _A_func)
     : base_type_(_A_func),
-      obj_ptr_derived_(&_A_obj), obj_ptr_(&_A_obj)
+      obj_(_A_obj)
     {}
 
   /** Execute the wrapped method operating on the stored instance.dnl
@@ -154,13 +113,12 @@
    * @return The return value of the method invocation.
    */
   T_return operator()(LOOP(typename type_trait<T_arg%1>::take _A_a%1, $1)) const
-    { return ( (obj_ptr_derived_)->*(this->func_ptr_))(LOOP(_A_a%1, $1)); }
+    { return (obj_.invoke().*(this->func_ptr_))(LOOP(_A_a%1, $1)); }
 
 //protected:
-  // Pointer to stored object instance.
+  // Reference to stored object instance.
   // This is the handler object, such as TheObject in void TheObject::signal_handler().
-  $3 T_obj* obj_ptr_derived_;
-  $3 sigc::trackable* obj_ptr_; //This, and its type is used by the visit_each<> specialization below.
+  [$2]limit_reference<T_obj> obj_;
 };
 
 //template specialization of visit_each<>(action, functor):
@@ -174,7 +132,7 @@
 void visit_each(const T_action& _A_action,
                 const bound_[$2]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))>& _A_target)
 {
-  sigc::visit_each(_A_action, *_A_target.obj_ptr_);
+  sigc::visit_each(_A_action, _A_target.obj_);
 }
 
 ])
@@ -228,7 +186,7 @@
 __FIREWALL__
 #include <sigc++/type_traits.h>
 #include <sigc++/functors/functor_trait.h>
-#include <sigc++/trackable.h>
+#include <sigc++/limit_reference.h>
 
 namespace sigc {
 
diff -uNr libsigc++-2.0.11-cvs/sigc++/macros/limit_reference.h.m4 libsigc++-2.0.11/sigc++/macros/limit_reference.h.m4
--- libsigc++-2.0.11-cvs/sigc++/macros/limit_reference.h.m4	1969-12-31 16:00:00.000000000 -0800
+++ libsigc++-2.0.11/sigc++/macros/limit_reference.h.m4	2005-05-07 00:38:37.000000000 -0700
@@ -0,0 +1,137 @@
+dnl
+dnl Copyright 2002, The libsigc++ Development Team 
+dnl 
+dnl This library is free software; you can redistribute it and/or 
+dnl modify it under the terms of the GNU Lesser General Public 
+dnl License as published by the Free Software Foundation; either 
+dnl version 2.1 of the License, or (at your option) any later version. 
+dnl 
+dnl This library is distributed in the hope that it will be useful, 
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
+dnl Lesser General Public License for more details. 
+dnl 
+dnl You should have received a copy of the GNU Lesser General Public 
+dnl License along with this library; if not, write to the Free Software 
+dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+dnl
+divert(-1)
+
+include(template.macros.m4)
+
+define([LIMIT_REFERENCE],[dnl
+/** [$1]limit_reference object for a class that does not derive from trackable.
+ * - @e T_type The type of the reference.
+ */
+template <class T_type,
+          bool I_derives_trackable =
+            is_base_and_derived<trackable, T_type>::value>
+class [$1]limit_reference
+{
+public:
+  /** Constructor.
+   * @param _A_target The reference to limit.
+   */
+  [$1]limit_reference([$2]T_type &_A_target)
+    : visited(_A_target)
+    {}
+
+  /** Retrieve the entity to visit in visit_each().
+   * @return The reference.
+   */
+  inline const T_type &visit() const
+    { return visited; }
+
+  /** Retrieve the reference.
+   * @return The reference.
+   */
+  inline [$3]T_type &invoke() const
+    { return visited; }
+
+private:
+  /** The reference.
+   */
+  [$2]T_type &visited;
+};
+
+/** [$1]limit_reference object for a class that derives from trackable.
+ * - @e T_type The type of the reference.
+ */
+template <class T_type>
+class [$1]limit_reference<T_type, true>
+{
+public:
+  /** Constructor.
+   * @param _A_target The reference to limit.
+   */
+  [$1]limit_reference([$2]T_type &_A_target)
+    : visited(_A_target),
+      invoked(_A_target)
+    {}
+
+  /** Retrieve the entity to visit in visit_each().
+   * @return The trackable reference.
+   */
+  inline const trackable &visit() const
+    { return visited; }
+
+  /** Retrieve the reference.
+   * @return The reference.
+   */
+  inline [$3]T_type &invoke() const
+    { return invoked; }
+
+private:
+  /** The trackable reference.
+   */
+  [$2]trackable &visited;
+
+  /** The reference.
+   */
+  [$2]T_type &invoked;
+};
+
+/** Implementation of visit_each() specialized for the [$1]limit_reference
+ * class. Call visit_each() on the entity returned by the [$1]limit_reference's
+ * visit() method.
+ * - @e T_action The type of functor to invoke.
+ * - @e T_type The type of the reference.
+ * @param _A_action The functor to invoke.
+ * @param _A_argument The visited instance.
+ */
+template <class T_action, class T_type>
+void
+visit_each(const T_action &_A_action,
+           const [$1]limit_reference<T_type> &_A_target)
+{
+  visit_each(_A_action, _A_target.visit());
+}
+])
+
+divert(0)
+
+__FIREWALL__
+
+
+#include <sigc++/type_traits.h>
+#include <sigc++/trackable.h>
+
+
+namespace sigc {
+
+
+LIMIT_REFERENCE([],[],[])dnl
+
+
+LIMIT_REFERENCE([const_],[const ],[const ])dnl
+
+
+LIMIT_REFERENCE([volatile_],[],[volatile ])dnl
+
+
+LIMIT_REFERENCE([const_volatile_],[const ],[const volatile ])dnl
+
+
+} /* namespace sigc */
+
+
diff -uNr libsigc++-2.0.11-cvs/sigc++/Makefile.am libsigc++-2.0.11/sigc++/Makefile.am
--- libsigc++-2.0.11-cvs/sigc++/Makefile.am	2004-03-21 15:45:56.000000000 -0800
+++ libsigc++-2.0.11/sigc++/Makefile.am	2005-05-07 00:38:37.000000000 -0700
@@ -1,9 +1,10 @@
 # Base (./)
 base_m4 = template.macros.m4 signal.h.m4 slot.h.m4 method_slot.h.m4 \
-	  object_slot.h.m4 class_slot.h.m4 hide.h.m4 retype.h.m4
+	  object_slot.h.m4 class_slot.h.m4 hide.h.m4 retype.h.m4 \
+	  limit_reference.h.m4
 base_built_cc =
 base_built_h = signal.h slot.h method_slot.h \
-	       object_slot.h class_slot.h hide.h retype.h
+	       object_slot.h class_slot.h hide.h retype.h limit_reference.h
 
 signal.cc : signal.h signal_base.h functors/slot.h functors/slot_base.h functors/mem_fun.h functors/functor_trait.h
 
diff -uNr libsigc++-2.0.11-cvs/sigc++/reference_wrapper.h libsigc++-2.0.11/sigc++/reference_wrapper.h
--- libsigc++-2.0.11-cvs/sigc++/reference_wrapper.h	2004-04-12 14:53:37.000000000 -0700
+++ libsigc++-2.0.11/sigc++/reference_wrapper.h	2005-05-07 00:38:37.000000000 -0700
@@ -36,6 +36,16 @@
   T_type& value_;
 };
 
+#if 0
+template <class T_action, class T_type>
+void
+visit_each(const T_action &_A_action,
+           const reference_wrapper<T_type> &_A_target)
+{
+   visit_each(_A_action, _A_target.value_);
+}
+#endif
+
 /** Const reference wrapper.
  * Use sigc::ref() to create a const reference wrapper.
  */
@@ -51,6 +61,16 @@
   const T_type& value_;
 };
 
+#if 0
+template <class T_action, class T_type>
+void
+visit_each(const T_action &_A_action,
+           const const_reference_wrapper<T_type> &_A_target)
+{
+   visit_each(_A_action, _A_target.value_);
+}
+#endif
+
 /** Creates a reference wrapper.
  * Passing an object throught sigc::ref() makes libsigc++ adaptors
  * like, e.g., sigc::bind store references to the object instead of copies.
@@ -97,6 +117,7 @@
   typedef const T_type& type;
 };
 
+#if 0
 template <class T_type>
 T_type& unwrap(T_type& v)
 { return v; }
@@ -104,6 +125,7 @@
 template <class T_type>
 const T_type& unwrap(const T_type& v)
 { return v; }
+#endif
 
 template <class T_type>
 T_type& unwrap(const reference_wrapper<T_type>& v)
diff -uNr libsigc++-2.0.11-cvs/sigc++/type_traits.h libsigc++-2.0.11/sigc++/type_traits.h
--- libsigc++-2.0.11-cvs/sigc++/type_traits.h	2005-04-30 17:50:45.000000000 -0700
+++ libsigc++-2.0.11/sigc++/type_traits.h	2005-05-07 00:38:37.000000000 -0700
@@ -19,7 +19,9 @@
 #ifndef _SIGC_TYPE_TRAIT_H_
 #define _SIGC_TYPE_TRAIT_H_
 
+#if 0
 #include <sigc++/reference_wrapper.h>
+#endif
 
 namespace sigc {
 
@@ -59,6 +61,7 @@
   typedef const T_type* pointer;
 };
 
+#if 0
 template <class T_type>
 struct type_trait<reference_wrapper<T_type> >
 {
@@ -76,6 +79,7 @@
   typedef const T_type& take;
   typedef T_type* pointer;
 };
+#endif
 
 template<>
 struct type_trait<void>
diff -uNr libsigc++-2.0.11-cvs/tests/Makefile.am libsigc++-2.0.11/tests/Makefile.am
--- libsigc++-2.0.11-cvs/tests/Makefile.am	2005-04-30 19:13:17.000000000 -0700
+++ libsigc++-2.0.11/tests/Makefile.am	2005-05-07 00:38:37.000000000 -0700
@@ -26,8 +26,7 @@
   test_bind_ref \
   test_functor_trait \
   test_compatibility \
-  test_virtualbase_delete \
-  test_virtualbase_delete_ref_param \
+  test_limit_reference \
   test_copy_invalid_slot \
   test_custom
 
@@ -64,7 +63,6 @@
 
 test_size_SOURCES = test_size.cc
 test_compatibility_SOURCES = test_compatibility.cc
-test_virtualbase_delete_SOURCES = test_virtualbase_delete.cc
-test_virtualbase_delete_ref_param_SOURCES = test_virtualbase_delete_ref_param.cc
+test_limit_reference_SOURCES = test_limit_reference.cc
 test_copy_invalid_slot_SOURCES = test_copy_invalid_slot.cc
 test_custom_SOURCES = test_custom.cc
diff -uNr libsigc++-2.0.11-cvs/tests/test_bind_ref.cc libsigc++-2.0.11/tests/test_bind_ref.cc
--- libsigc++-2.0.11-cvs/tests/test_bind_ref.cc	2005-04-26 23:40:03.000000000 -0700
+++ libsigc++-2.0.11/tests/test_bind_ref.cc	2005-05-07 00:38:27.000000000 -0700
@@ -27,7 +27,7 @@
 
 int main()
 {
-  sigc::slot< void, sigc::reference_wrapper<Param> > slot_full = sigc::ptr_fun(&handler);
+  sigc::slot<void, Param &> slot_full = sigc::ptr_fun(&handler);
   sigc::slot<void> slot_bound;
 
   //slot_bound();
@@ -35,6 +35,8 @@
   {
     //Because Param derives from sigc::trackable(), sigc::ref() should disconnect the signal handler when param is destroyed.
     Param param("murrayc");
+    // A convoluted way to do
+    // slot_bound = sigc::bind(slot_full, sigc::ref(param));
     slot_bound = sigc::bind< -1, sigc::reference_wrapper<Param> >(slot_full, sigc::ref(param));
 
     std::cout << "Calling slot when param exists:" << std::endl;
diff -uNr libsigc++-2.0.11-cvs/tests/test_bind_return.cc libsigc++-2.0.11/tests/test_bind_return.cc
--- libsigc++-2.0.11-cvs/tests/test_bind_return.cc	2005-01-19 10:23:38.000000000 -0800
+++ libsigc++-2.0.11/tests/test_bind_return.cc	2005-05-07 00:38:33.000000000 -0700
@@ -31,12 +31,23 @@
 {
   std::cout << sigc::bind_return(foo(),-12345)(5) << std::endl;
 
-  // test references
+  // Here we just build a functor, not a slot. There is no such thing as a
+  // default functor, or an invalidated functor. As such, functors can return
+  // references.
   std::string str("guest book");
-  sigc::bind_return<std::string&>(foo(),str)(6) = "main";
+  // A convoluted way to do
+  // sigc::bind_return(foo(), sigc::ref(str))(6) = "main";
+  sigc::bind_return<sigc::reference_wrapper<std::string> >(foo(), sigc::ref(str))(6) = "main";
   std::cout << str << std::endl;
 
-  sigc::slot<bar,int> sl; // bar, not bar&: slots cannot return references
+  // Here we build a slot (constructed from a functor). Slots cannot return
+  // references: if they could, then what would be the return value of the
+  // default slot or of an invalidated slot? On the other hand, slots are
+  // guaranteed to be able to construct and return a valid default instance as
+  // long as there exists a default constructor for it.
+  //
+  // Therefore, we use 'bar', and not 'bar &' for this slot signature.
+  sigc::slot<bar,int> sl;
   {
     bar choco(-1);
     sl = sigc::bind_return(foo(),sigc::ref(choco));
diff -uNr libsigc++-2.0.11-cvs/tests/test_custom.cc libsigc++-2.0.11/tests/test_custom.cc
--- libsigc++-2.0.11-cvs/tests/test_custom.cc	2005-04-30 19:12:08.000000000 -0700
+++ libsigc++-2.0.11/tests/test_custom.cc	2005-05-07 00:38:37.000000000 -0700
@@ -1,41 +1,14 @@
-#include <sigc++/sigc++.h>
-
-
-class Base : virtual public sigc::trackable
-{
-public:
-  
-};
-
-class Base2
-{
-public:
-  virtual ~Base2()
-  {}
-};
+// Write your custom tests here so you don't have to think about how to compile
+// and execute your test code against the exact same library that you are
+// currently hacking.
 
+#include <sigc++/sigc++.h>
 
-class Derived
-  : virtual public Base,
-    public Base2
-{
-public:
-  Derived()
-  {
-    
-  }
-};
 
-void handler(Derived &dlg)
-{}
 
 int main(int argc, char **argv)
 {
-  sigc::signal<void> signal_something;
-
-  Derived* param = new Derived();
-  signal_something.connect(sigc::bind( sigc::ptr_fun(&handler), sigc::ref(*param) ));
-  delete param;
+  
 
   return 0;
 }
diff -uNr libsigc++-2.0.11-cvs/tests/test_limit_reference.cc libsigc++-2.0.11/tests/test_limit_reference.cc
--- libsigc++-2.0.11-cvs/tests/test_limit_reference.cc	1969-12-31 16:00:00.000000000 -0800
+++ libsigc++-2.0.11/tests/test_limit_reference.cc	2005-05-07 00:38:37.000000000 -0700
@@ -0,0 +1,35 @@
+#include <sigc++/sigc++.h>
+
+class Base
+  : virtual public sigc::trackable
+{
+};
+
+class Base2
+{
+public:
+  virtual ~Base2()
+  {}
+};
+
+class Derived
+  : virtual public Base,
+    public Base2
+{
+public:
+  void method()
+  {}
+};
+
+int main(int argc, char **argv)
+{
+  Derived *instance = new Derived();
+  sigc::slot<void> handler = sigc::mem_fun(instance, &Derived::method);
+  sigc::slot<void> param =
+    sigc::bind(sigc::slot<void, Derived &>(), sigc::ref(*instance));
+  sigc::slot<Derived> ret =
+    sigc::bind_return(sigc::slot<void>(), sigc::ref(*instance));
+  delete instance;
+
+  return 0;
+}
diff -uNr libsigc++-2.0.11-cvs/tests/test_virtualbase_delete.cc libsigc++-2.0.11/tests/test_virtualbase_delete.cc
--- libsigc++-2.0.11-cvs/tests/test_virtualbase_delete.cc	2005-04-28 01:07:04.000000000 -0700
+++ libsigc++-2.0.11/tests/test_virtualbase_delete.cc	1969-12-31 16:00:00.000000000 -0800
@@ -1,38 +0,0 @@
-#include <sigc++/sigc++.h>
-
-
-class Base : virtual public sigc::trackable
-{
-public:
-   sigc::signal<void> signal_something;
-};
-
-class Base2
-{
-public:
-  virtual ~Base2()
-  {}
-};
-
-class Derived
-  : virtual public Base,
-    public Base2
-{
-public:
-  Derived()
-  {
-     signal_something.connect(sigc::mem_fun(this, &Derived::handler));
-  }
-
-private:
-   void handler()
-   {}
-};
-
-int main(int argc, char **argv)
-{
-   Derived* instance = new Derived();
-   delete instance;
-
-   return 0;
-}
diff -uNr libsigc++-2.0.11-cvs/tests/test_virtualbase_delete_ref_param.cc libsigc++-2.0.11/tests/test_virtualbase_delete_ref_param.cc
--- libsigc++-2.0.11-cvs/tests/test_virtualbase_delete_ref_param.cc	2005-04-30 19:12:15.000000000 -0700
+++ libsigc++-2.0.11/tests/test_virtualbase_delete_ref_param.cc	1969-12-31 16:00:00.000000000 -0800
@@ -1,41 +0,0 @@
-#include <sigc++/sigc++.h>
-
-
-class Base : virtual public sigc::trackable
-{
-public:
-  
-};
-
-class Base2
-{
-public:
-  virtual ~Base2()
-  {}
-};
-
-
-class Derived
-  : virtual public Base,
-    public Base2
-{
-public:
-  Derived()
-  {
-    
-  }
-};
-
-void handler(Derived &dlg)
-{}
-
-int main(int argc, char **argv)
-{
-  sigc::signal<void> signal_something;
-
-  Derived* param = new Derived();
-  signal_something.connect(sigc::bind( sigc::ptr_fun(&handler), sigc::ref(*param) ));
-  delete param;
-
-  return 0;
-}
