A fix is available
APAR status
Closed as program error.
Error description
When compiling and running the provided testcase, the compiler produces a warning message indicating that you are trying to return the address of a local variable within the return expression. However, in the source code itself, the code is only trying to return the value returned by a function call. !* TEST CASE !* --------- !* !* testcase_xlC_10.cpp: !* #include "string.h" !* !* char *isUltimateAnswer(char *szAsciiz, int * piNum) !* { !* if (*piNum == 42) !* strcpy(szAsciiz, "Yes"); !* else !* strcpy(szAsciiz, "No"); !* return szAsciiz; !* } !* char * AskDeepThought(char *szAsciiz) !* { !* int iNum = 1; !* !* return isUltimateAnswer(szAsciiz, &iNum); !* } !* !* !* ACTUAL OUTPUT !* ------------- !* !* "testcase_xlC_10.cpp", line 16.39: 1540-1103 (W) The address !* of a local variable or temporary is used in a return !* expression. !* !*
Local fix
Create an intermediary object within the 'AskDeepThought' function char * AskDeepThought(char *szAsciiz) { int iNum = 1; char *szRet = isUltimateAnswer(szAsciiz, &iNum); return szRet; }
Problem summary
PROBLEM DESCRIPTION: Incorrect compiler warning about returning the address of a local. USERS AFFECTED: Return statement passing the address of a local to a function that is used to return a pointer/reference.
Problem conclusion
Backported fix from v11.
Temporary fix
Comments
APAR Information
APAR number
IZ76950
Reported component name
XL C++ AIX
Reported component ID
5724U8100
Reported release
A10
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt
Submitted date
2010-06-04
Closed date
2010-10-05
Last modified date
2010-10-05
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++ AIX
Fixed component ID
5724U8100
Applicable component levels
[{"Line of Business":{"code":"LOB08","label":"Cognitive Systems"},"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"A.1"}]
Document Information
Modified date:
07 October 2021