Whether capacity of strings shrinks depends on whether the strings are shared. 
I believe this also true for 4.0.1, but I only have the sources of it, didn't
compile.

To reproduce (note that `s2' is not shared at the time of push):

int
main()
{
  string s1;
  s1.reserve (10000);

  string s2 = s1;

  s1.push_back ('!');
  s2.push_back ('!');

  cout << "s1 capacity: " << s1.capacity () << endl;
  cout << "s2 capacity: " << s2.capacity () << endl;

  return 0;
}


Output (here):

s1 capacity: 1
s2 capacity: 12259

-- 
           Summary: std::basic_string <> capacity weirdness
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pogonyshev at gmx dot net
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to