[smart_ptr] make_shared perfect forwarding bug

Perfect forwarding doesn't seem to work quite correctly with boost::make_shared. The attached program, which tries to pass a move-only type through make_shared fails to compile with gcc in c++0x mode. To fix it, I had to change the definition of detail::forward in make_shared.hpp to use rvalue references: #if defined( BOOST_HAS_RVALUE_REFS ) template< class T > T&& forward( T &&t ) { return t; } #endif This is just based on looking at how gcc implements std::forward. Is this the right fix?

Frank Mori Hess:
Perfect forwarding doesn't seem to work quite correctly with boost::make_shared. The attached program, which tries to pass a move-only type through make_shared fails to compile with gcc in c++0x mode. To fix it, I had to change the definition of detail::forward in make_shared.hpp to use rvalue references:
#if defined( BOOST_HAS_RVALUE_REFS ) template< class T > T&& forward( T &&t ) { return t; } #endif
This is just based on looking at how gcc implements std::forward. Is this the right fix?
Yes, I believe so. My original forward was incorrect. (We should probably switch to std::forward at some point.)
participants (2)
-
Frank Mori Hess
-
Peter Dimov