-
Notifications
You must be signed in to change notification settings - Fork 141
Description
Currently the following code leads to crash/undefined behavior with tsl::robin_map:
int main ()
{
tsl::robin_map<int, std::string> v;
v[0] = "23";
for (int i = 2; i < 3300; ++i)
v[i] = v[0];
}It happens because we pass the reference to our own element which gets destroyed during reallocation and since construction happens late it leads to the unfortunate results. I understand that this might be a design decision to treat it as UB however I have the following reason for suggesting to fix this:
-
It works fine with node-based (
std::) maps. -
It works with
std::vector. I can't quote standard paragraph exactly but here's link to the statement from Microsoft of fixing this problem in their implementation https://devblogs.microsoft.com/cppblog/stl-fixes-in-vs-2017-rtm/ (Fixed aliasing bugs) -
It actually seems to be much more frequent operation for unordered map rather than for vector, simply copying a past value to the newly created field feels like natural operation in many cases.
-
A fix seems to be the same as for vector since it is the structure robin map built upon so should not be that hard to implement.