http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48728
Summary: cannot construct a vector of unique_ptr from an initializer list Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: john.sal...@deshaw.com I think the problem here is that the vector constructor is trying to invoke a copy-constructor to create the elements of the vector from the elements of the initializer list. But there is no copy-constructor for a unique_ptr. According to Table 97 of the FCD, the elements, T, need only be MoveConstructible, not CopyConstructible, so I think the library is wrong to invoke the copy constructor. salm...@drdlogin0039.en.desres$ cat v.cpp #include <memory> #include <vector> struct Foo{ int i; }; typedef std::unique_ptr<Foo> up; std::vector<up> bad{up{new Foo}, up{new Foo}}; salm...@drdlogin0039.en.desres$ desres-cleanenv -m gcc/4.6.0-23A/bin g++ -v -save-temps -std=c++0x -Wall -c -o v.o v.cpp Reading specs from /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/specs COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /state/partition1/tmp/desres-install.158e2ef1dc69/gcc-4.6.0-23A/gcc-4.6.0/configure --prefix=/proj/desres/root/Linux/x86_64/gcc/4.6.0-23A --with-local-prefix=/proj/desres/root/Linux/x86_64/gcc/4.6.0-23A/local --enable-languages=c,c++,fortran,java Thread model: posix gcc version 4.6.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-Wall' '-c' '-o' 'v.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/cc1plus -E -quiet -v -iprefix /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/ -D_GNU_SOURCE v.cpp -mtune=generic -march=x86-64 -std=c++0x -Wall -fpch-preprocess -o v.ii ignoring nonexistent directory "/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../x86_64-unknown-linux-gnu/include" ignoring duplicate directory "/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0" ignoring duplicate directory "/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/x86_64-unknown-linux-gnu" ignoring duplicate directory "/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/backward" ignoring duplicate directory "/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/include" ignoring nonexistent directory "/proj/desres/root/Linux/x86_64/gcc/4.6.0-23A/local/include" ignoring duplicate directory "/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/include-fixed" ignoring nonexistent directory "/proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../x86_64-unknown-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0 /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/x86_64-unknown-linux-gnu /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/backward /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/include /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/include-fixed /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/../../include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-Wall' '-c' '-o' 'v.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/cc1plus -fpreprocessed v.ii -quiet -dumpbase v.cpp -mtune=generic -march=x86-64 -auxbase-strip v.o -Wall -std=c++0x -version -o v.s GNU C++ (GCC) version 4.6.0 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.6.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (GCC) version 4.6.0 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.6.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 5005a2e86ab024b8579a7b8cfdb44c26 In file included from /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/memory:66:0, from v.cpp:1: /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/stl_construct.h: In function 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = std::unique_ptr<Foo>, _Args = {const std::unique_ptr<Foo>&}]': /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/stl_uninitialized.h:77:3: instantiated from 'static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = const std::unique_ptr<Foo>*, _ForwardIterator = std::unique_ptr<Foo>*, bool _TrivialValueTypes = false]' /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/stl_uninitialized.h:119:41: instantiated from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = const std::unique_ptr<Foo>*, _ForwardIterator = std::unique_ptr<Foo>*]' /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/stl_uninitialized.h:259:63: instantiated from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = const std::unique_ptr<Foo>*, _ForwardIterator = std::unique_ptr<Foo>*, _Tp = std::unique_ptr<Foo>]' /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/stl_vector.h:1113:4: instantiated from 'void std::vector<_Tp, _Alloc>::_M_range_initialize(_ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = const std::unique_ptr<Foo>*, _Tp = std::unique_ptr<Foo>, _Alloc = std::allocator<std::unique_ptr<Foo> >]' /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/stl_vector.h:312:2: instantiated from 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::unique_ptr<Foo>, _Alloc = std::allocator<std::unique_ptr<Foo> >, std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::unique_ptr<Foo> >]' v.cpp:9:45: instantiated from here /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/stl_construct.h:76:7: error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = Foo, _Dp = std::default_delete<Foo>, std::unique_ptr<_Tp, _Dp> = std::unique_ptr<Foo>]' /proj/desrad-c/root/Linux/x86_64/gcc/4.6.0-23A/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.6.0/../../../../include/c++/4.6.0/bits/unique_ptr.h:254:7: error: declared here salm...@drdlogin0039.en.desres$