Skip to content

Instantly share code, notes, and snippets.

@cjhanks
Last active October 4, 2016 22:22
Show Gist options
  • Save cjhanks/c92e31d1851c6c985939f452779798d5 to your computer and use it in GitHub Desktop.
Save cjhanks/c92e31d1851c6c985939f452779798d5 to your computer and use it in GitHub Desktop.
FailCase
#include <cassert>
#include <iostream>
#include <map>
#include <unordered_map>
template <typename Map>
void
Remove(Map map)
{
assert(map.size() == 1);
for (auto it = std::begin(map);
it != std::end(map);
) {
it = map.erase(it);
}
}
int
main()
{
std::unordered_map<int, int> map1 { {0, 0} };
std::map<int, int> map2 { {0, 0} };
Remove(map1);
Remove(map2);
return 0;
}
@cjhanks
Copy link
Author

cjhanks commented Oct 3, 2016

Failing error:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000404515 in std::_Hashtable<int, std::pair<int const, int>, std::allocator<std::pair<int const, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_get_previous_node(unsigned long, std::__detail::_Hash_node_base*) ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment