[Bug libstdc++/52938] std::string::reserve request is not maintained if object is used in other object copy ctor

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Apr 13 08:31:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52938

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-13 08:31:13 UTC ---
> The user could care less if we use copy-on-write in the string implementation. 
> The standard doesn't force that (21.3.6).  

But it does allow it.

> We are violating what the standard says about reserve (20.3.10/20.3.11).  Here
> it is:
> "Effects: after reserve(), capacity() is greater or equal to the argument of
> reserve".
> 
> That is it.  if I call reserve(1024) on a string, from that point on, capacity 
> should return at least 1024. 

Immediately after you call reserve it returns at least 1024.  But not
necessarily from that point on for ever and ever.  If you call swap() to
exchange it with another string it's capacity could shrink, or in C++11 if you
move assign another string to it its capacity could change. Or, in C++03 for
reference-counted strings, it could change because the previously-shared string
is no longer shared.

This is a pointless discussion anyway, it's not going to change.



More information about the Gcc-bugs mailing list