[Bug libstdc++/105717] New: [9/10/11/12/13 Regression] cannot create unordered_map from range of types convertible to value_type
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue May 24 10:29:36 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105717
Bug ID: 105717
Summary: [9/10/11/12/13 Regression] cannot create unordered_map
from range of types convertible to value_type
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
CC: unassigned at gcc dot gnu.org
Target Milestone: ---
+++ This bug was initially created as a clone of Bug #56112 +++
François observed that I fixed construction for PR 56112, but we still don't
support insertion of such types:
#include <unordered_map>
#include <utility>
#include <assert.h>
struct Key
{
explicit Key(const int* p) : value(p) { }
~Key() { value = nullptr; }
bool operator==(const Key& k) const
{ return *value == *k.value; }
const int* value;
};
struct hash
{
std::size_t operator()(const Key& k) const noexcept
{ return *k.value; }
};
struct S
{
static int _count;
int value;
operator std::pair<const Key, int>() const
{
++_count;
return { Key(&value), value };
}
};
int S::_count = 0;
int main()
{
S s[1] = { {2} };
std::unordered_map<Key, int, hash> m(s, s + 1);
assert( S::_count == 1 );
std::unordered_multimap<Key, int, hash> mm(s, s + 1);
assert( S::_count == 2 );
m.insert(s, s + 1);
assert( S::_count == 3 );
mm.insert(s, s + 1);
assert( S::_count == 4 );
}
This worked in 4.7
More information about the Gcc-bugs
mailing list