[smart_ptr] extra colon on make_shared variadic template instantiation

Hi, while instantiating this template, the Intel compiler finds that there is an extra colon when Args is empty. ::new( pv ) T( boost::detail::sp_forward<Arg1>( arg1 ), boost::detail::sp_forward<Args>( args )... ); ^ Is this a bug on the compiler or on Boost.SmartPtr? Best, Vicente template< class T, class Arg1, class... Args > typename boost::detail::sp_if_not_array< T >::type make_shared( Arg1 && arg1, Args && ... args ) { boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) ); boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() ); void * pv = pd->address(); ::new( pv ) T( boost::detail::sp_forward<Arg1>( arg1 ), boost::detail::sp_forward<Args>( args )... ); pd->set_initialized(); T * pt2 = static_cast< T* >( pv ); boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 ); return boost::shared_ptr< T >( pt, pt2 ); }

Le 17/09/13 19:45, Vicente J. Botet Escriba a écrit :
Hi, could I commit this patch pc3:smart_ptr viboes$ svn diff Index: make_shared_object.hpp =================================================================== --- make_shared_object.hpp (revision 85776) +++ make_shared_object.hpp (working copy) @@ -207,6 +207,23 @@ // Variadic templates, rvalue reference +template< class T, class... Args > typename boost::detail::sp_if_not_array< T >::type make_shared( Args && ... args ) +{ + boost::shared_ptr< T > pt( static_cast< T* >( 0 ), BOOST_SP_MSD( T ) ); + + boost::detail::sp_ms_deleter< T > * pd = static_cast<boost::detail::sp_ms_deleter< T > *>( pt._internal_get_untyped_deleter() ); + + void * pv = pd->address(); + + ::new( pv ) T( boost::detail::sp_forward<Args>( args )... ); + pd->set_initialized(); + + T * pt2 = static_cast< T* >( pv ); + + boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 ); + return boost::shared_ptr< T >( pt, pt2 ); +} + Vicente

Vicente J. Botet Escriba wrote:
I have no idea where an extra colon could come from, but maybe you mean an extra comma. This should be a compiler bug.
I'm not sure how this could help. This overload is either ambiguous with the Arg1&& one, or less specialized. Do the make_shared tests pass on all compilers after the patch? The reason that there are two overloads, one without arguments, the other with Arg1&& and Args&&..., is that earlier versions of g++ treated new T(args...) as new T when args... is empty, instead of the correct new T(). There is a test that checks for this bug. If the current crop of supported compilers no longer suffers from it, the two overloads can be replaced by the simple variadic Args... version. But adding the Args... version in addition to the other two makes no sense to me.

On 19 September 2013 08:53, Peter Dimov wrote:
FWIW that should be fixed in G++ 4.3.0 onwards: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32597

Le 19/09/13 09:53, Peter Dimov a écrit :
I recognize that it should be a better solution. I have compiled with gcc-4.5 and newer, clang-3.1+3.2 and Intel 12.1.3 Not tested with MSVC :( Best, Vicente
participants (3)
-
Jonathan Wakely
-
Peter Dimov
-
Vicente J. Botet Escriba