[cfe-dev] libc++ and clang++3.2: cannot have make_shared work properly

Howard Hinnant hhinnant at apple.com
Thu Jun 14 07:48:25 PDT 2012


In C++03 mode make_shared only accepts up to 3 arguments, and they all must be lvalues.  Either do:

   std::make_shared<int>(i);

or turn on C++11:  -std=c++11

Howard


On Jun 11, 2012, at 9:37 AM, Akim Demaille wrote:

> Hi all,
> 
> Using clang++ 3.2 and libc++ from MacPorts, I can't use make_shared.
> Maybe I missed something?
> 
> $ cat foo.cc
> #include <memory>
> 
> int
> main()
> {
>  std::make_shared<int>(1);
> }
> $ clang++-mp-3.2 --version
> clang version 3.2 (trunk 157234)
> Target: x86_64-apple-darwin11.4.0
> Thread model: posix
> $ clang++-mp-3.2 -Wall -std=c++11 -stdlib=libc++ foo.cc
> In file included from foo.cc:1:
> /usr/include/c++/v1/memory:1815:31: error: constructor cannot be redeclared
>    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
>                              ^
> /usr/include/c++/v1/memory:1919:15: note: in instantiation of template class 'std::__1::__libcpp_compressed_pair_imp<std::__1::allocator<int>, int, 1>' requested here
>    : private __libcpp_compressed_pair_imp<_T1, _T2>
>              ^
> /usr/include/c++/v1/memory:2641:36: note: in instantiation of template class 'std::__1::__compressed_pair<std::__1::allocator<int>, int>' requested here
>    __compressed_pair<_Alloc, _Tp> __data_;
>                                   ^
> /usr/include/c++/v1/memory:3114:26: note: in instantiation of template class 'std::__1::__shared_ptr_emplace<int, std::__1::allocator<int>>' requested here
>    ::new(__hold2.get()) _CntrlBlk(__a2, _STD::forward<_Args>(__args)...);
>                         ^
> /usr/include/c++/v1/memory:3429:12: note: in instantiation of function template specialization 'std::__1::shared_ptr<int>::make_shared<int>' requested here
>    return shared_ptr<_Tp>::make_shared(_STD::forward<_Args>(__args)...);
>           ^
> foo.cc:6:3: note: in instantiation of function template specialization 'std::__1::make_shared<int, int>' requested here
>  std::make_shared<int>(1);
>  ^
> /usr/include/c++/v1/memory:1811:40: note: previous declaration is here
>    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0)
>                                       ^
> /usr/include/c++/v1/memory:1937:31: error: constructor cannot be redeclared
>    _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
>                              ^
> /usr/include/c++/v1/memory:2641:36: note: in instantiation of template class 'std::__1::__compressed_pair<std::__1::allocator<int>, int>' requested here
>    __compressed_pair<_Alloc, _Tp> __data_;
>                                   ^
> /usr/include/c++/v1/memory:3114:26: note: in instantiation of template class 'std::__1::__shared_ptr_emplace<int, std::__1::allocator<int>>' requested here
>    ::new(__hold2.get()) _CntrlBlk(__a2, _STD::forward<_Args>(__args)...);
>                         ^
> /usr/include/c++/v1/memory:3429:12: note: in instantiation of function template specialization 'std::__1::shared_ptr<int>::make_shared<int>' requested here
>    return shared_ptr<_Tp>::make_shared(_STD::forward<_Args>(__args)...);
>           ^
> foo.cc:6:3: note: in instantiation of function template specialization 'std::__1::make_shared<int, int>' requested here
>  std::make_shared<int>(1);
>  ^
> /usr/include/c++/v1/memory:1933:40: note: previous declaration is here
>    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1, int = 0)
>                                       ^
> 2 errors generated.
> $
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list