https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80858
Bug ID: 80858
Summary: When trying to copy std::unordered_map illegally,
error message doesn't tell what's wrong
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sgunderson at bigfoot dot com
Target Milestone: ---
Using gcc version 7.1.0 (Debian 7.1.0-5) (but the error goes back to at least
4.8, and amazingly, also in Clang), on this piece of code, simplified from a
much bigger test case:
#include <memory>
#include <unordered_map>
int main(void)
{
std::unordered_map<int, std::unique_ptr<int>> a, b;
a = b;
}
The code is wrong, and GCC correctly rejects it, but the error message is less
than helpful, since it doesn't mention the line with the assignment on, or
really anything hinting at who asked the copy constructor to be invoked:
$ g++-7 -c test.cc
In file included from
/usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
from /usr/include/c++/7/bits/allocator.h:46,
from /usr/include/c++/7/memory:63,
from test.cc:1:
/usr/include/c++/7/ext/new_allocator.h: In instantiation of ‘void
__gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up =
std::pair<const int, std::unique_ptr<int> >; _Args = {const std::pair<const
int, std::unique_ptr<int, std::default_delete<int> > >&}; _Tp = std::pair<const
int, std::unique_ptr<int> >]’:
/usr/include/c++/7/bits/alloc_traits.h:475:4: required from ‘static void
std::allocator_traits<std::allocator<_Tp1>
>::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&,
_Up*, _Args&& ...) [with _Up = std::pair<const int, std::unique_ptr<int> >;
_Args = {const std::pair<const int, std::unique_ptr<int,
std::default_delete<int> > >&}; _Tp = std::pair<const int, std::unique_ptr<int>
>; std::allocator_traits<std::allocator<_Tp1> >::allocator_type =
std::allocator<std::pair<const int, std::unique_ptr<int> > >]’
/usr/include/c++/7/bits/hashtable_policy.h:2066:37: required from
‘std::__detail::_Hashtable_alloc<_NodeAlloc>::__node_type*
std::__detail::_Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&& ...)
[with _Args = {const std::pair<const int, std::unique_ptr<int,
std::default_delete<int> > >&}; _NodeAlloc =
std::allocator<std::__detail::_Hash_node<std::pair<const int,
std::unique_ptr<int> >, false> >;
std::__detail::_Hashtable_alloc<_NodeAlloc>::__node_type =
std::__detail::_Hash_node<std::pair<const int, std::unique_ptr<int> >, false>]’
/usr/include/c++/7/bits/hashtable.h:1023:54: required from
‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash,
_RehashPolicy, _Traits>::operator=(const std::_Hashtable<_Key, _Value, _Alloc,
_ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>&)::<lambda(const
__node_type*)> [with _Key = int; _Value = std::pair<const int,
std::unique_ptr<int> >; _Alloc = std::allocator<std::pair<const int,
std::unique_ptr<int> > >; _ExtractKey = std::__detail::_Select1st; _Equal =
std::equal_to<int>; _H1 = std::hash<int>; _H2 =
std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash;
_RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits =
std::__detail::_Hashtable_traits<false, false, true>; std::_Hashtable<_Key,
_Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_Traits>::__node_type = std::__detail::_Hash_node<std::pair<const int,
std::unique_ptr<int> >, false>; typename _Traits::__hash_cached =
std::integral_constant<bool, false>]’
/usr/include/c++/7/bits/hashtable.h:1022:9: required from ‘struct
std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash,
_RehashPolicy, _Traits>::operator=(const std::_Hashtable<_Key, _Value, _Alloc,
_ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>&) [with _Key =
int; _Value = std::pair<const int, std::unique_ptr<int> >; _Alloc =
std::allocator<std::pair<const int, std::unique_ptr<int> > >; _ExtractKey =
std::__detail::_Select1st; _Equal = std::equal_to<int>; _H1 = std::hash<int>;
_H2 = std::__detail::_Mod_range_hashing; _Hash =
std::__detail::_Default_ranged_hash; _RehashPolicy =
std::__detail::_Prime_rehash_policy; _Traits =
std::__detail::_Hashtable_traits<false, false, true>]::<lambda(const
__node_type*)>’
/usr/include/c++/7/bits/hashtable.h:1021:14: required from
‘std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash,
_RehashPolicy, _Traits>& std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey,
_Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>::operator=(const
std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash,
_RehashPolicy, _Traits>&) [with _Key = int; _Value = std::pair<const int,
std::unique_ptr<int> >; _Alloc = std::allocator<std::pair<const int,
std::unique_ptr<int> > >; _ExtractKey = std::__detail::_Select1st; _Equal =
std::equal_to<int>; _H1 = std::hash<int>; _H2 =
std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash;
_RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits =
std::__detail::_Hashtable_traits<false, false, true>]’
/usr/include/c++/7/bits/unordered_map.h:101:11: required from here
/usr/include/c++/7/ext/new_allocator.h:136:4: error: use of deleted function
‘std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const int;
_T2 = std::unique_ptr<int>]’
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
from /usr/include/c++/7/memory:62,
from test.cc:1:
/usr/include/c++/7/bits/stl_pair.h:292:17: note: ‘std::pair<_T1,
_T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const int; _T2 =
std::unique_ptr<int>]’ is implicitly deleted because the default definition
would be ill-formed:
constexpr pair(const pair&) = default;
^~~~
/usr/include/c++/7/bits/stl_pair.h:292:17: error: use of deleted function
‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with
_Tp = int; _Dp = std::default_delete<int>]’
In file included from /usr/include/c++/7/memory:80:0,
from test.cc:1:
/usr/include/c++/7/bits/unique_ptr.h:388:7: note: declared here
unique_ptr(const unique_ptr&) = delete;
^~~~~~~~~~