[Bug libstdc++/39416] std::map::operator[] inserts a new item in RHS context
--- Comment #3 from pinskia at gcc dot gnu dot org 2009-03-09 21:28 --- It is hard for the library to know if we are doing an insert or doing an extract as there is only one type of operator[] really. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39416
[Bug libstdc++/39416] std::map::operator[] inserts a new item in RHS context
--- Comment #2 from glyn at adgie dot f9 dot co dot uk 2009-03-09 21:25 --- Thanks Paolo, I suspected that this was not a bug in libstdc++, but standard-compliant behaviour. It just seems so unexpected, when compared to other languages that have maps, e.g. tables in Lua. It is also unexpected when compared to other STL containers, e.g. std::vector. A bug in the standard, perhaps? I would have thought that if other languages can implement the expected behaviour for reading from an associative array, so should C++. Perhaps there is something in the implementation of std::map that makes this impossible or inefficient, but I must say, I cannot see why. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39416
[Bug libstdc++/39416] std::map::operator[] inserts a new item in RHS context
--- Comment #1 from paolo dot carlini at oracle dot com 2009-03-09 20:53 --- There is nothing wrong here, the bahavior is fully specified in the Standard, 23.3.1.2 as: Returns: (*((insert(make_pair(x, T(.first)).second. Note, our inline documentation comments are also very clear about this. -- paolo dot carlini at oracle dot com changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39416