sparsepp icon indicating copy to clipboard operation
sparsepp copied to clipboard

SEGV after moving hash_map

Open diameter opened this issue 6 years ago • 2 comments

Linux/Darwin gcc/clang MWE

spp::sparse_hash_map<uint64_t, uint64_t> map0;
map0.emplace(0, 0);
auto map1 = std::move(map0);
//map0 = spp::sparse_hash_map<uint64_t, uint64_t>{}; // uncomment this to pass the test
auto found = map0.find(0); // segfaults here
CHECK(found == end(map0));

diameter avatar Sep 17 '19 12:09 diameter

What is the intended behavior here? A moved-from object is generally assumed to be in an undefined state. Presumably, this means that it can still be validly-destructed, but you can't do much else with it. I guess, the most robust behavior would be for the moved-from map to be empty ; is that what you would expect? Any thoughts @greg7mdp?

rob-p avatar Jan 08 '20 02:01 rob-p

@rob-p yes indeed the moved-from object should be in a consistent state, so this is a bug. I'll look into it when I have some time. In the meanwhile maybe phmap is a good alternative.

greg7mdp avatar Jan 08 '20 02:01 greg7mdp