Fixes are available
APAR status
Closed as program error.
Error description
A problem occurs when inlining a function from an include file that uses static data, while using compiler optimization. In some cases, multiple copies of the static variable occur instead of the single instance expected. === TEST CASE === ---------------------------------------------------------------- apar1.cpp: #include <apar3.h> #include <iostream> int main() { std::cout << Derived::GetStr() << "\n"; } ---------------------------------------------------------------- apar2.cpp: #include <apar3.h> void Derived::InitStr() { GetStr() = "Derived class did this."; } ---------------------------------------------------------------- apar3.h: #ifndef INCLUDED_APAR3 #define INCLUDED_APAR3 #include <string> template <typename Derived> struct Base { static std::string& GetStr(); virtual ~Base() { } }; template <typename Derived> std::string& Base<Derived>::GetStr() { static std::string str = "Base class did this."; static bool init = false; if (!init) { init = true; Derived::InitStr(); } return str; } struct Derived : public Base<Derived> { static void InitStr(); }; #endif ---------------------------------------------------------------- Output: $ xlC -I. apar1.cpp apar2.cpp -O3 apar1.cpp: apar2.cpp: $ ./a.out Base class did this. $ Expected Output: $ xlC -I. apar1.cpp apar2.cpp -O3 apar1.cpp: apar2.cpp: $ ./a.out Derived class did this. $
Local fix
Lower optimization level.
Problem summary
PROBLEM DESCRIPTION: Inlined function is duplicating static variable. USERS AFFECTED: Users of inlining with optimization and static variables in header files.
Problem conclusion
The problem has been resolved.
Temporary fix
Comments
APAR Information
APAR number
IJ04431
Reported component name
XL C FOR AIX
Reported component ID
5725C7100
Reported release
D10
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt / Xsystem
Submitted date
2018-03-01
Closed date
2018-03-02
Last modified date
2018-03-02
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
XL C FOR AIX
Fixed component ID
5725C7100
Applicable component levels
RD10 PSY
UP
[{"Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSGH2K","label":"XL C for AIX"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"13.1"}]
Document Information
Modified date:
14 September 2021