http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55123
Bug #: 55123 Summary: [C++11] Construction of shared_ptr<const T> from unique_ptr<const T> fails Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: yegor.dereven...@gmail.com Hello, construction of a shared_ptr from a unique_ptr to a const object seems not to work, although it should. Preprocessed file is attached. [yegor@tomato tmp]$ cat test.cpp #include <memory> void f() { std::unique_ptr<const int> y; std::shared_ptr<const int> x = std::move(y); } [yegor@tomato tmp]$ g++ -c -std=c++11 -save-temps test.cpp In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/x86_64-unknown-linux-gnu/bits/c++allocator.h:34:0, from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/allocator.h:48, from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/memory:65, from test.cpp:1: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ext/new_allocator.h: In instantiation of ‘struct __gnu_cxx::new_allocator<const int>’: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/allocator.h:89:11: required from ‘class std::allocator<const int>’ /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr_base.h:329:14: required from ‘struct std::_Sp_counted_deleter<const int*, std::default_delete<const int>, std::allocator<const int>, (__gnu_cxx::_Lock_policy)2u>::_My_Deleter’ /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr_base.h:374:24: required from ‘class std::_Sp_counted_deleter<const int*, std::default_delete<const int>, std::allocator<const int>, (__gnu_cxx::_Lock_policy)2u>’ /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr_base.h:625:39: required from ‘static std::_Sp_counted_base<_Lp>* std::__shared_count<_Lp>::_S_create_from_up(std::unique_ptr<_Up, _Ep>&&, typename std::enable_if<(! std::is_reference<_Del>::value)>::type*) [with _Tp = const int; _Del = std::default_delete<const int>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u; typename std::enable_if<(! std::is_reference<_Del>::value)>::type = void]’ /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr_base.h:549:43: required from ‘std::__shared_count<_Lp>::__shared_count(std::unique_ptr<_Up, _Ep>&&) [with _Tp = const int; _Del = std::default_delete<const int>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’ /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr_base.h:855:4: required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Tp1 = const int; _Del = std::default_delete<const int>; _Tp = const int; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’ /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr.h:259:36: required from ‘std::shared_ptr<_Tp>::shared_ptr(std::unique_ptr<_Up, _Ep>&&) [with _Tp1 = const int; _Del = std::default_delete<const int>; _Tp = const int]’ test.cpp:5:44: required from here /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ext/new_allocator.h:83:7: error: ‘const _Tp* __gnu_cxx::new_allocator<_Tp>::address(__gnu_cxx::new_allocator<_Tp>::const_reference) const [with _Tp = const int; __gnu_cxx::new_allocator<_Tp>::const_pointer = const int*; __gnu_cxx::new_allocator<_Tp>::const_reference = const int&]’ cannot be overloaded /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ext/new_allocator.h:79:7: error: with ‘_Tp* __gnu_cxx::new_allocator<_Tp>::address(__gnu_cxx::new_allocator<_Tp>::reference) const [with _Tp = const int; __gnu_cxx::new_allocator<_Tp>::pointer = const int*; __gnu_cxx::new_allocator<_Tp>::reference = const int&]’ [yegor@tomato tmp]$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /build/src/gcc-4.7.2/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --disable-ppl-version-check --disable-cloog-version-check --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --enable-multilib --disable-libssp --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-checking=release Thread model: posix gcc version 4.7.2 (GCC)