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

abdul.tohmaz at emc dot com gcc-bugzilla@gcc.gnu.org
Fri Apr 13 13:38:00 GMT 2012


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

--- Comment #14 from Abdul Tohmaz <abdul.tohmaz at emc dot com> 2012-04-13 13:37:47 UTC ---
(In reply to comment #13)

> 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.

I agree with you on this discussion being pointless.
I am looking at this from the end user perspective and what the standards
dictates while you are looking at from the way gcc implements string.  Your
point about C++11 doesn't apply here (completely different ball game).  The
standard doesn't say anything about capacity for swap (21.3.5.8).  The user
expects the standard to be followed and when it says that capacity to be >= to
the reserve argument, he certainly expects that.  Unless you can show me
somewhere in the standards where it says the requested capacity via reserve
calls may be affected by copy constructor in the case an implementer chose to
use copy-on-write.  That is all I ask.



More information about the Gcc-bugs mailing list