A fix is available
APAR status
Closed as program error.
Error description
The behaviour of std::vector in the test case below gets unexpected if optimization is turned on. It appears that when an insert is attempted after erase, the first element is not getting pushed forward to the second position. I am if sure if this is a runtime or a compiler issue. Starting against the library. . Testcase: ========== . #include <stdio.h> #include <string> #include <map> #include <vector> . using namespace std; . typedef map<string, int, less<string> > MAP; typedef vector<MAP::iterator> VECTOR; typedef pair<MAP::iterator, bool> INSRESULT; . void print(MAP&, VECTOR&); . int main(){ MAP m; VECTOR v; INSRESULT p; . // Insert three elements p = m.insert(MAP::value_type("A", 100)); v.insert(v.begin(), p.first); . p = m.insert(MAP::value_type("B", 200)); v.insert(v.begin()+v.size(), p.first); . p = m.insert(MAP::value_type("C", 300)); v.insert(v.begin(), p.first); . print(m, v); . m.erase(v[1]); v.erase(v.begin()+1); printf("\nRemoved first element from m and v\n"); . print(m, v); . printf("\nInsert (D,400) to m and v\n"); p = m.insert(MAP::value_type("D", 400)); v.insert(v.begin(), p.first); . print(m, v); } . void print(MAP &m, VECTOR &v){ int i = 0; int vlen = v.size(); . printf("\nMap: "); for(MAP::iterator it = m.begin(); it!=m.end(); it++){ printf("\tm[%d] @0x%x: (%s,%d)\n", i, &(*it), (*it).first.data(), (*it).second); i++; } . printf("Vector:"); for(i=0; i<vlen; i++){ printf("\tv[%d] @0x%x: (%s,%d)\n", i, &v[i], (*v[i]).first.data(), (*v[i]).second); } } . . xlC -O -qalias=noansi t.cpp . . Output: ======== Map: m[0] @0x2020a5a4: (A,100) m[1] @0x2020a614: (B,200) m[2] @0x2020a684: (C,300) Vector: v[0] @0x2020a6a8: (C,300) v[1] @0x2020a6ac: (A,100) v[2] @0x2020a6b0: (B,200) . Removed first element from m and v . Map: m[0] @0x2020a614: (B,200) m[1] @0x2020a684: (C,300) Vector: v[0] @0x2020a6a8: (C,300) v[1] @0x2020a6ac: (B,200) . Insert (D,400) to m and v . Map: m[0] @0x2020a614: (B,200) m[1] @0x2020a684: (C,300) m[2] @0x2020a5a4: (D,400) Vector: v[0] @0x2020a6a8: (D,400) v[1] @0x2020a6ac: (B,200) <-- Should be C,300 v[2] @0x2020a6b0: (B,200) . If optmization is turned off, v[1] will contain (C,300) as expected. .
Local fix
Disable optimization of the affected module.
Problem summary
The problem cause has been traced to a line of code in the C++ standard library header xutility, at function copy_backward. The problem was caused by the compiler optimizater component, not an error in the runtime code.
Problem conclusion
The problem has been fixed in the coming VAC++ V5 PTF.
Temporary fix
Comments
APAR Information
APAR number
IY44051
Reported component name
VA C++ PROF FOR
Reported component ID
5765F5600
Reported release
600
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt / Xsystem
Submitted date
2003-05-05
Closed date
2003-05-05
Last modified date
2007-04-30
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
Fix information
Fixed component name
VA C++ PROF FOR
Fixed component ID
5765F5600
Applicable component levels
R600 PSN U810710
UP07/04/30 I 1000
Fix is available
Select the PTF appropriate for your component level. You will be required to sign in. Distribution on physical media is not available in all countries.
[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSO198","label":"IBM Visualage C++ Professional for AIX"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"6.0","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]
Document Information
Modified date:
20 August 2024