This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Abdul Tohmaz <abdul.tohmaz at emc dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|WONTFIX                     |

--- Comment #7 from Abdul Tohmaz <abdul.tohmaz at emc dot com> 2012-04-11 23:53:04 UTC ---
Guys, I do value your points, but please consider the following:
I can't always be in control when a copy is made of my string.  Here is a quick
example.

string x;
x.reserve(1024); //no memory realloc for my string up to 1024
x="aaa";  
x+= "bb";  // so far no memory realloc.

//now I call a function by third party library whose
//signature is void doit(const string&).  
doit(x);

x+= "cc";  //I am expecting no memory realloc here.

//but in fact the last statement will reallocate memory if 
//doit put a copy of my string in a vector:  ex
//void doit (const std::string& val){ vec.push_back(val);}

Don't you think this is a problem?  I called reserve on x to avoid memory
reallocation, and yet I am faced with memory reallocation just because I call
doit; whose signature (const ref) suggests that my object should not be
changed.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]