APAR status
Closed as program error.
Error description
When compiling with optimization with INLINE enabled, auto_ptr usage with copy constructors is resulting in incorrect auto_ptr behaviour. Specifically, the object being copied is destructed during the new auto_ptr initialization instead of transferring ownership of the pointer. === TEST CASE === #include <memory> #include <vector> class Base { public: Base(): Val1(1) {} ~Base() { printf("dctor '%08X' --> ", this); } int GetVal1() { return Val1; } protected: int Val1; }; class Derived : public Base { public: Derived() : Val2(2) {} int GetVal2() { return Val2; } protected: int Val2; }; class Derived2 : public Derived { public: Derived2() : Val3(3) {} int GetVal3() { return Val3; } protected: int Val3; }; std::auto_ptr<Derived2> func1() { std::auto_ptr<Derived2> pObj2(new Derived2); printf("pDerived2='%08X'; Val2='%d' --> ", pObj2.get(), pObj2->GetVal2()); return pObj2; } void func2() { std::vector<Derived*> arrObj; for (int i = 0; i < 10; i++) { std::auto_ptr<Derived> pObj(func1()); printf("pDerived='%08X'; Val2='%d'\n", pObj.get(), pObj->GetVal2()); arrObj.push_back(pObj.release()); } for (int i = 0; i < arrObj.size(); i++) { delete arrObj[i]; } } int main(int argc,char* argv[]) { func2(); return 0; } === INCORRECT OUTPUT === > xlC -O2 test.cpp ./a.out pDerived2='25B50D20'; Val2='2' --> dctor '25B50D20' --> pDerived='25B50D20'; Val2='0' pDerived2='25B50D30'; Val2='2' --> dctor '25B50D30' --> pDerived='25B50D30'; Val2='0' pDerived2='25B50D40'; Val2='2' --> dctor '25B50D40' --> pDerived='25B50D40'; Val2='0' pDerived2='25B50D20'; Val2='2' --> dctor '25B50D20' --> pDerived='25B50D20'; Val2='0' pDerived2='25B50D38'; Val2='2' --> dctor '25B50D38' --> pDerived='25B50D38'; Val2='0' pDerived2='25B50D20'; Val2='2' --> dctor '25B50D20' --> pDerived='25B50D20'; Val2='0' pDerived2='25B50D20'; Val2='2' --> dctor '25B50D20' --> pDerived='25B50D20'; Val2='0' pDerived2='25B50D20'; Val2='2' --> dctor '25B50D20' --> pDerived='25B50D20'; Val2='0' pDerived2='25B50D20'; Val2='2' --> dctor '25B50D20' --> pDerived='25B50D20'; Val2='0' pDerived2='25B50D20'; Val2='2' --> dctor '25B50D20' --> pDerived='25B50D20'; Val2='0' dctor '25B50D20' --> dctor '25B50D30' --> dctor '25B50D40' --> dctor '25B50D20' --> dctor '25B50D38' --> dctor '25B50D20' --> dctor '25B50D20' --> dctor '25B50D20' --> dctor '25B50D20' --> dctor '25B50D20' --> > === CORRECT OUTPUT === >./a.out pDerived2='25B50D20'; Val2='2' --> pDerived='25B50D20'; Val2='2' pDerived2='25B50D48'; Val2='2' --> pDerived='25B50D48'; Val2='2' pDerived2='25B50D70'; Val2='2' --> pDerived='25B50D70'; Val2='2' pDerived2='25B50DA0'; Val2='2' --> pDerived='25B50DA0'; Val2='2' pDerived2='25B50D88'; Val2='2' --> pDerived='25B50D88'; Val2='2' pDerived2='25B50DB8'; Val2='2' --> pDerived='25B50DB8'; Val2='2' pDerived2='25B50DF0'; Val2='2' --> pDerived='25B50DF0'; Val2='2' pDerived2='25B50DD0'; Val2='2' --> pDerived='25B50DD0'; Val2='2' pDerived2='25B50E38'; Val2='2' --> pDerived='25B50E38'; Val2='2' pDerived2='25B50E50'; Val2='2' --> pDerived='25B50E50'; Val2='2' dctor '25B50D20' --> dctor '25B50D48' --> dctor '25B50D70' --> dctor '25B50DA0' --> dctor '25B50D88' --> dctor '25B50DB8' --> dctor '25B50DF0' --> dctor '25B50DD0' --> dctor '25B50E38' --> dctor '25B50E50' --> >
Local fix
- Do not use optimization - Compile with option NOANSIALIAS - Manually modify code to call the 'release()' method of the auto_ptr used in the copy constructor/initialization
Problem summary
Problem conclusion
Using -D__IBMCPP_AUTO_PTR_REF_CONVS will now enable a new implementation of auto_ptr_ref which contains an additional member in order to encode the necessary information to reliably retrieve the auto_ptr to which it refers. The new implementation is not binary-compatible with the old one.
Temporary fix
Comments
RECOMMENDATION TO CUSTOMER: If auto_ptr_ref--including symbols for its member functions--is not exposed in binary interfaces requiring compatibility with the old implementation of auto_ptr_ref, then enable the new implementation of auto_ptr_ref by applying the header update and compile all code using auto_ptr_ref (explicitly or otherwise) with -D__IBMCPP_AUTO_PTR_REF_CONVS.
APAR Information
APAR number
PI44519
Reported component name
C/C++ FOR MVS
Reported component ID
56551210A
Reported release
790
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt / Xsystem
Submitted date
2015-07-07
Closed date
2015-12-17
Last modified date
2016-03-09
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
Modules/Macros
CRTEC128
Fix information
Fixed component name
ANSI C++ CLASS
Fixed component ID
568819807
Applicable component levels
R790 PSY
UP
[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SG19M","label":"APARs - z\/OS environment"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"790","Edition":"","Line of Business":{"code":"","label":""}},{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSTLTF","label":"z\/OS XL C\/C++"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"790","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]
Document Information
Modified date:
09 March 2016