https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90192
Bug ID: 90192 Summary: std::vector<T>::resize() requires more than the CopyInsertable Product: gcc Version: 8.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: lemo1234 at gmail dot com Target Milestone: --- std::vector<T>::resize(size_type count, const value_type& value) requires CopyInsertable, but recent libstdc++ versions try to use the assignment operator (https://godbolt.org/z/xrutNZ) #include <vector> struct X { const int c; }; void foo() { std::vector<X> v; v.resize(10, X{}); } n file included from /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/vector:60, from <source>:2: /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<(! std::__is_scalar<_Tp>::__value), void>::__type std::__fill_a(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = X*; _Tp = X; typename __gnu_cxx::__enable_if<(! std::__is_scalar<_Tp>::__value), void>::__type = void]': /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h:731:20: required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = X*; _Tp = X]' /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/vector.tcc:505:14: required from 'void std::vector<_Tp, _Alloc>::_M_fill_insert(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = X; _Alloc = std::allocator<X>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<X*, std::vector<X> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = X*; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = X]' /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_vector.h:847:4: required from 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = X; _Alloc = std::allocator<X>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = X]' <source>:8:21: required from here /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h:685:11: error: use of deleted function 'X& X::operator=(const X&)' *__first = __value; ~~~~~~~~~^~~~~~~~~ <source>:4:8: note: 'X& X::operator=(const X&)' is implicitly deleted because the default definition would be ill-formed: struct X { const int c; }; ^ <source>:4:8: error: non-static const member 'const int X::c', can't use default assignment operator In file included from /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/vector:60, from <source>:2: /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h: In instantiation of 'static _Tp* std::__copy_move_backward<_IsMove, true, std::random_access_iterator_tag>::__copy_move_b(const _Tp*, const _Tp*, _Tp*) [with _Tp = X; bool _IsMove = true]': /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h:588:37: required from '_BI2 std::__copy_move_backward_a(_BI1, _BI1, _BI2) [with bool _IsMove = true; _BI1 = X*; _BI2 = X*]' /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h:598:5: required from '_BI2 std::__copy_move_backward_a2(_BI1, _BI1, _BI2) [with bool _IsMove = true; _BI1 = X*; _BI2 = X*]' /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h:668:48: required from '_BI2 std::move_backward(_BI1, _BI1, _BI2) [with _BI1 = X*; _BI2 = X*]' /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/vector.tcc:503:5: required from 'void std::vector<_Tp, _Alloc>::_M_fill_insert(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = X; _Alloc = std::allocator<X>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<X*, std::vector<X> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = X*; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = X]' /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_vector.h:847:4: required from 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = X; _Alloc = std::allocator<X>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = X]' <source>:8:21: required from here /opt/compiler-explorer/gcc-8.3.0/include/c++/8.3.0/bits/stl_algobase.h:566:19: error: static assertion failed: type is not assignable static_assert( __assignable::type::value, "type is not assignable" ); ^~~~~~~~~~~~ Compiler returned: 1