IBM Support

LI71159: Compiler error 1540-0216 due to compiler rejecting const_cast for an array

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • Compiler reports error for the following test case. It compiles
    fine if a scalar int is used.
    
    
    typedef int IntArray[2];
    
    void fakeFunc(IntArray &) { }
    
    void constCastArray() {
       const IntArray i = { 1, 2 };
       fakeFunc(const_cast<IntArray &>(i));
    }
    
    $ xlC const_int_array_test.cxx
    "const_int_array_test.hxx", line 5.41: 1540-0216 (S) An
    expression of type "const IntArray" cannot be converted to type
    "IntArray &".
    

Local fix

  • n/a
    

Problem summary

  • USER AFFECTED:
    Users of const_cast with const arrays
    casting to non-const array references.
    
    PROBLEM DESCRIPTION:
    Compiler generate unnecessary error message
    
    EXPECTED ERROR:
    1540-0216 (S) An expression of type "const IntArray"
    cannot be converted to type "IntArray
    &".
    When working, there should be no error.
    
    WORKAROUND:
    Use old-style casts like:
    
    So if it looks like:
       static_cast<X*>(&a)
    
    It can be replaced by:
       (X*)(&a)
    

Problem conclusion

  • Can be fixed for both the one and higher
    dimensoin case.
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI71159

  • Reported component name

    XL C/C++ SLES9

  • Reported component ID

    5724K7700

  • Reported release

    700

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2006-01-10

  • Closed date

    2006-01-12

  • Last modified date

    2006-01-12

  • APAR is sysrouted FROM one or more of the following:

    IY78555

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL C/C++ SLES9

  • Fixed component ID

    5724K7700

Applicable component levels

  • R700 PSY

       UP

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7.0","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
16 October 2021