libstdc++, debug mode: resizing a vector doesn't update capacity

Bug #769601 reported by Arne Redlich
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Fix Released
Medium
gcc-4.4 (Ubuntu)
Won't Fix
Low
Unassigned

Bug Description

Binary package hint: gcc-4.4

Bug details / code to reproduce / fix can be found in the upstream bug report:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44190

Even though this upstream bug report was filed against gcc-4.5, it's also present / reproducible with libstdc++6-4.4-dev, version 4.4.3-4ubuntu5 on Ubuntu 10.04.

Revision history for this message
In , Gcc-bugzilla (gcc-bugzilla) wrote :

The assertion in the following testcase should /not/ fail, but does:

  #define _GLIBCXX_DEBUG
  #define _GLIBCXX_DEBUG_PEDANTIC

  #include <vector>
  #include <cassert>

  int main()
  {
    std::vector<int> v;
    v.resize(10);
    assert(v.size() <= v.capacity());
  }

Revision history for this message
In , Gcc-bugzilla (gcc-bugzilla) wrote :

Created attachment 20695
Trivial patch that fixes the problem.

The problem was just a missing call to _M_update_guaranteed_capacity().

Revision history for this message
In , Paolo-carlini (paolo-carlini) wrote :

I'm going to apply the patch: could you please provide name and family name for the ChangeLog entry? Thanks!

Revision history for this message
In , Gcc-bugzilla (gcc-bugzilla) wrote :

(In reply to comment #2)
> I'm going to apply the patch

Great, thanks! :)

> could you please provide name and family name for
> the ChangeLog entry?

It's "Eelis van der Weegen"

Revision history for this message
In , Paolo-k (paolo-k) wrote :

Subject: Bug 44190

Author: paolo
Date: Tue May 18 23:58:50 2010
New Revision: 159549

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159549
Log:
2010-05-18 Eelis van der Weegen <email address hidden>

 PR libstdc++/44190
 * include/debug/vector (vector<>::resize): Call
 _M_update_guaranteed_capacity.
 * testsuite/23_containers/vector/capacity/44190.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/debug/vector

Revision history for this message
In , Paolo-carlini (paolo-carlini) wrote :

Fixed.

Revision history for this message
In , Mikpe (mikpe) wrote :

This bug also affects 4.5 and 4.4, but not 4.3, making it a regression from 4.3. The fix for 4.6 backports cleanly to 4.5 and with minor fuzz to 4.4, and has been verified to fix the problem on those branches too with no new testsuite regressions (bootstrapped + regtested on i686-linux).

Revision history for this message
In , Paolo-carlini (paolo-carlini) wrote :

How it can possibly not affect 4.3? The code is exactly the same.

Revision history for this message
In , Mikpe (mikpe) wrote :

I just compiled the original test case with 4.5, 4.4, and 4.3, and the assert didn't trigger when compiled with 4.3. I didn't investigate any further.

Revision history for this message
In , Paolo-carlini (paolo-carlini) wrote :

Given the identical resize code, missing a real analysis of why the patch is needed in mainline and isn't in 4.3, I don't feel comfortable committing the patch to the older branches, since nobody else complained so far and in general the pedantic mode is much less used.

Revision history for this message
In , Paolo-carlini (paolo-carlini) wrote :

Ok, now I see, vector::capacity itself has been changed between 4.3 and 4.4. Let's apply the patch to 4.5 too.

Revision history for this message
In , Paolo-k (paolo-k) wrote :

Subject: Bug 44190

Author: paolo
Date: Wed May 19 12:08:53 2010
New Revision: 159560

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159560
Log:
2010-05-19 Eelis van der Weegen <email address hidden>

 PR libstdc++/44190
 * include/debug/vector (vector<>::resize): Call
 _M_update_guaranteed_capacity.
 * testsuite/23_containers/vector/capacity/44190.cc: New.

Added:
    branches/gcc-4_5-branch/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc
Modified:
    branches/gcc-4_5-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_5-branch/libstdc++-v3/include/debug/vector

Revision history for this message
In , Mikpe (mikpe) wrote :

(In reply to comment #10)
> Let's apply the patch to 4.5 too.

Thanks!

Revision history for this message
Dave Gilbert (ubuntu-treblig) wrote :

Still broken in the g++-4.4 in Quantal:

dg@major:~$ g++-4.4 x.cpp -g -O2

dg@major:~$ ./a.out
a.out: x.cpp:11: int main(): Assertion `v.size() <= v.capacity()' failed.
Aborted (core dumped)

4.5,4.6,4.7 all seem good.

Changed in gcc-4.4 (Ubuntu):
importance: Undecided → Low
status: New → Triaged
Micah Gersten (micahg)
tags: added: rls-q-incoming
Changed in gcc:
importance: Unknown → Medium
status: Unknown → Fix Released
Revision history for this message
Colin Watson (cjwatson) wrote :

21:34 <slangasek> micahg: same question on bug #769601... not sure what the impact is here
21:34 <slangasek> (marked 'low', and nobody's said it's breaking any of the handful of packages that depend on g++-4.4)
01:47 <micahg> slangasek: I marked the nih one to make sure it wasn't missed on the release team's radar, the gcc issue seems to only affect 4.4, was just wondering if this was something that might be worth fixing since apparently the same patch with fuzz applies, no inherent interest from me in either fix
01:52 <slangasek> micahg: ok - declining to commit to fixing either then :)

tags: added: rls-q-notfixing
removed: rls-q-incoming
Revision history for this message
Matthias Klose (doko) wrote :

closing as won't fix for 4.4

Changed in gcc-4.4 (Ubuntu):
status: Triaged → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.