Bug 57774

Summary: libstdc++-devel-2.96-85 provides STL container std::map, size() does not properly increment via operator[], only insert() works correctly.
Product: [Retired] Red Hat Linux Reporter: D. Stimits <stimits>
Component: libstdc++Assignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: stimits
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-11-24 14:25:36 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description D. Stimits 2001-12-21 21:28:46 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.4.6-pre1-xfs-4 i686)

Description of problem:
There are two means of inserting new elements into std::map, one via
literal insert(), the other via operator[]. In the latter case if an
element of key already exists, it merely updates the value and does not
change size(). If the element does not exist, it creates a new element and
increments size(). This fails and never increments to size beyond 1. It
should always update size() to match the number of keys present. Test case
was via std::map<std::string,std::string>, e.g., my_map["some_element"] =
"new value" (prior to this assert that key "some_element" cannot be found).

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. Check a std::map size().
2. Verify that an element of key type (about to be inserted) does not
exist.
3. Use operator[] notation to add a new key and value pair.
4. Verify size() has incremented by 1.
5. Repeat with a new key; size() will never increment over 1, but should
reflect the total number of keys (use of iterators will prove the key and
value pairs do exist and that there is more than 1 element in the map).


Actual Results:  size() never shows greater than 1 if inserts are done via
operator[].

Expected Results:  size() must always reflect the number of elements in the
std::map.

Additional info:

Use of the literal operator insert() does successfully and correctly
increment size. If it is necessary to know the number of elements in the
map, operator[] cannot be used without introducing a false size().

NOTE: There is no bugzilla list for libstdc++-devel, it is necessary to
report it instead under libstdc++. Tested version is
libstdc++-devel-2.96-85, g++ 2.96. In addition to the bug fix,
libstdc++devel should be added as a package in bugzilla.

Comment 1 Benjamin Kosnik 2004-10-01 15:27:05 UTC
No code to reproduce, cannot tell if a bug in implementation or usage.

Please provide a test case.

-benjamin

Comment 2 Jakub Jelinek 2004-11-24 14:25:36 UTC
If you have a testcase, please reopen.