public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107022] New: error: use of deleted function 'std::unordered_map
@ 2022-09-23 21:58 piersh at hotmail dot com
2022-09-23 22:00 ` [Bug c++/107022] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: piersh at hotmail dot com @ 2022-09-23 21:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
Bug ID: 107022
Summary: error: use of deleted function 'std::unordered_map
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: piersh at hotmail dot com
Target Milestone: ---
this is a regression in newer point-releases of gcc (this bug got backported).
it appears first in 10.4, 11.2.1 and 12.x. 10.3 and 11.2.0 do not have this
issue.
#include <unordered_map>
#include <memory>
struct key {};
struct foo
{
struct my_hash
{
my_hash(int i = 42) {}
std::size_t operator()(const key &ep) const { return 0; }
};
private:
std::unordered_map<key, std::weak_ptr<std::string>, foo::my_hash>
things_{};
};
<source>:15:79: error: use of deleted function 'std::unordered_map<_Key, _Tp,
_Hash, _Pred, _Alloc>::unordered_map() [with _Key = key; _Tp =
std::weak_ptr<std::__cxx11::basic_string<char> >; _Hash = foo::my_hash; _Pred =
std::equal_to<key>; _Alloc = std::allocator<std::pair<const key,
std::weak_ptr<std::__cxx11::basic_string<char> > > >]'
15 | std::unordered_map<key, std::weak_ptr<std::string>, foo::my_hash>
things_{};
|
^
In file included from
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/unordered_map:47,
from <source>:1:
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/unordered_map.h:141:7:
note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map()
[with _Key = key; _Tp = std::weak_ptr<std::__cxx11::basic_string<char> >; _Hash
= foo::my_hash; _Pred = std::equal_to<key>; _Alloc =
std::allocator<std::pair<const key,
std::weak_ptr<std::__cxx11::basic_string<char> > > >]' is implicitly deleted
because the default definition would be ill-formed:
141 | unordered_map() = default;
| ^~~~~~~~~~~~~
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/unordered_map.h:141:7:
error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc,
_ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy,
_Traits>::_Hashtable() [with _Key = key; _Value = std::pair<const key,
std::weak_ptr<std::__cxx11::basic_string<char> > >; _Alloc =
std::allocator<std::pair<const key,
std::weak_ptr<std::__cxx11::basic_string<char> > > >; _ExtractKey =
std::__detail::_Select1st; _Equal = std::equal_to<key>; _Hash = foo::my_hash;
_RangeHash = std::__detail::_Mod_range_hashing; _Unused =
std::__detail::_Default_ranged_hash; _RehashPolicy =
std::__detail::_Prime_rehash_policy; _Traits =
std::__detail::_Hashtable_traits<true, false, true>]'
In file included from
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/unordered_map:46:
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/hashtable.h:529:7:
note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash,
_RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = key;
_Value = std::pair<const key, std::weak_ptr<std::__cxx11::basic_string<char> >
>; _Alloc = std::allocator<std::pair<const key,
std::weak_ptr<std::__cxx11::basic_string<char> > > >; _ExtractKey =
std::__detail::_Select1st; _Equal = std::equal_to<key>; _Hash = foo::my_hash;
_RangeHash = std::__detail::_Mod_range_hashing; _Unused =
std::__detail::_Default_ranged_hash; _RehashPolicy =
std::__detail::_Prime_rehash_policy; _Traits =
std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted
because the default definition would be ill-formed:
529 | _Hashtable() = default;
| ^~~~~~~~~~
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/hashtable.h:529:7:
error: use of deleted function 'constexpr
std::_Enable_default_constructor<false, _Tag>::_Enable_default_constructor()
[with _Tag = std::__detail::_Hash_node_base]'
In file included from
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/hashtable.h:36:
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/enable_special_members.h:113:15:
note: declared here
113 | constexpr _Enable_default_constructor() noexcept = delete;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
@ 2022-09-23 22:00 ` pinskia at gcc dot gnu.org
2022-09-23 22:05 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-23 22:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is another when is the inner type complete and the constructor can be used
issues really.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
2022-09-23 22:00 ` [Bug c++/107022] " pinskia at gcc dot gnu.org
@ 2022-09-23 22:05 ` pinskia at gcc dot gnu.org
2022-09-23 22:14 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-23 22:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Mainly read bug 102199 comment #7
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
2022-09-23 22:00 ` [Bug c++/107022] " pinskia at gcc dot gnu.org
2022-09-23 22:05 ` pinskia at gcc dot gnu.org
@ 2022-09-23 22:14 ` redi at gcc dot gnu.org
2022-09-23 22:16 ` piersh at hotmail dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-09-23 22:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, and the standard says that instantiating std::unordered_map with
incomplete types is undefined.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
` (2 preceding siblings ...)
2022-09-23 22:14 ` redi at gcc dot gnu.org
@ 2022-09-23 22:16 ` piersh at hotmail dot com
2022-09-23 22:21 ` piersh at hotmail dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: piersh at hotmail dot com @ 2022-09-23 22:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #4 from piersh at hotmail dot com ---
is it related to nested classes? this reproduces the issue: uncomment line 9 to
repro:
#include <unordered_map>
#include <memory>
struct key {};
struct my_hash
{
my_hash() {}
//my_hash(int i = 42) {} // <<-- uncomment for bug
std::size_t operator()(const key &ep) const { return 0; }
};
struct foo
{
foo();
private:
std::unordered_map<key, int, my_hash> things_;
};
foo::foo() {}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
` (3 preceding siblings ...)
2022-09-23 22:16 ` piersh at hotmail dot com
@ 2022-09-23 22:21 ` piersh at hotmail dot com
2022-09-23 22:22 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: piersh at hotmail dot com @ 2022-09-23 22:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #5 from piersh at hotmail dot com ---
oh, no. scratch that last comment.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
` (4 preceding siblings ...)
2022-09-23 22:21 ` piersh at hotmail dot com
@ 2022-09-23 22:22 ` pinskia at gcc dot gnu.org
2022-10-21 7:24 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-23 22:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to piersh from comment #4)
> struct my_hash
> {
> my_hash() {}
> my_hash(int i = 42) {} // <<-- uncomment for bug
> std::size_t operator()(const key &ep) const { return 0; }
> };
That is because my_hash constructor call with no arguments is ambigous at that
point. If you define one or the other constructor, it is no longer ambigous. If
you define both, the code is invalid.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
` (5 preceding siblings ...)
2022-09-23 22:22 ` pinskia at gcc dot gnu.org
@ 2022-10-21 7:24 ` pinskia at gcc dot gnu.org
2022-10-21 14:03 ` jens.maurer at gmx dot net
2022-10-21 15:08 ` redi at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-21 7:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jens.maurer at gmx dot net
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 107340 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
` (6 preceding siblings ...)
2022-10-21 7:24 ` pinskia at gcc dot gnu.org
@ 2022-10-21 14:03 ` jens.maurer at gmx dot net
2022-10-21 15:08 ` redi at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: jens.maurer at gmx dot net @ 2022-10-21 14:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #8 from Jens Maurer <jens.maurer at gmx dot net> ---
I understand we're in a tangled web of partially-complete class rules here,
but the standard does give you the expectation that the inner class is complete
at its closing brace:
[class.pre] p2 says:
"A class is considered defined after the closing brace of its class-specifier
has been seen even though its member functions are in general not yet defined."
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/107022] error: use of deleted function 'std::unordered_map
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
` (7 preceding siblings ...)
2022-10-21 14:03 ` jens.maurer at gmx dot net
@ 2022-10-21 15:08 ` redi at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-10-21 15:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107022
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
For the example in comment 0 the default-initializer for things_{} is the
problem, removing the {} allows it to compile.
For the example in Bug 107340 the problem is the default-initializer x = 0 in
the nested class, removing that allows it to compile.
The nested class is complete at the closing } but its complete class contexts
are not complete until the enclosing class is complete. default-initializers
and nested classes do not work well.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-10-21 15:08 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23 21:58 [Bug c++/107022] New: error: use of deleted function 'std::unordered_map piersh at hotmail dot com
2022-09-23 22:00 ` [Bug c++/107022] " pinskia at gcc dot gnu.org
2022-09-23 22:05 ` pinskia at gcc dot gnu.org
2022-09-23 22:14 ` redi at gcc dot gnu.org
2022-09-23 22:16 ` piersh at hotmail dot com
2022-09-23 22:21 ` piersh at hotmail dot com
2022-09-23 22:22 ` pinskia at gcc dot gnu.org
2022-10-21 7:24 ` pinskia at gcc dot gnu.org
2022-10-21 14:03 ` jens.maurer at gmx dot net
2022-10-21 15:08 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).