--- Comment #8 from gcc_bugzilla dot 20 dot marcelitom at inboxclean dot
com 2010-02-10 21:23 ---
Thanks Paolo. I did understand that map was passing a . I wrongly
assumed that it was using it to copy the pointed string to the map, but I
learned from your first post that it was only cop
--- Comment #7 from paolo dot carlini at oracle dot com 2010-02-10 10:18
---
To be sure: is is fully clear to you that a map stores a pair
of *pointer to const char* and an int? It does *not* store a full string, it
stores an *address* (and an int)!
--
http://gcc.gnu.org/bugzilla/s
--- Comment #6 from paolo dot carlini at oracle dot com 2010-02-10 10:16
---
There are many details to this, but note that if you stay away from c_str(),
and const char*, thus you consistently use C++ style strings, nothing
unexpected happens, *ever*.
--
http://gcc.gnu.org/bugzilla
--- Comment #5 from gcc_bugzilla dot 20 dot marcelitom at inboxclean dot
com 2010-02-10 04:00 ---
Thanks Andrew and Paolo, apologies for my mistake. I have learnt something.
According to what you wrote, a "seemingly natural" code like
for(;;) {
sElement = SomeString(...);
i
--- Comment #4 from paolo dot carlini at oracle dot com 2010-02-09 23:51
---
Grr, I noticed another typo in my reply, I meant of course "third find", not
"first find". Only the outcome of the third find was at issue, anyway.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43014
--- Comment #3 from paolo dot carlini at oracle dot com 2010-02-09 23:40
---
Oops, read "because in this case the address" as "THUS in this case the
address", sorry.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43014
--- Comment #2 from paolo dot carlini at oracle dot com 2010-02-09 23:20
---
The "surprising" behavior is ultimately due to the fact that our string is
reference counted, thus 'string aux = sElement' is a shallow copy, but then,
when sElement = "ab3" is performed a deep copy takes place
--- Comment #1 from pinskia at gcc dot gnu dot org 2010-02-09 22:48 ---
I don't think this is a bug. sElement.c_str() returns a temporary storage
which gets destroyed when sElement changes (via the operator= method).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43014