IBM Support

IV85614: ISSUES WITH THROWN EXCEPTIONS

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • The compiler is incorrectly processing the nested exceptions for
    the following test case:
    
    ===== COMPILE COMMAND:
    xlC_r test.cpp
    
    ===== TESTCASE:
    $ cat test.cpp
    #include <iostream>
    
    namespace uncaught
    {
    class CheckUncaught
    {
    public:
    static bool s_checked;
    static bool s_uncaught;
    
    CheckUncaught()
    {
    s_checked = false;
    s_uncaught = false;
    }
    
    ?CheckUncaught()
    {
    s_checked = true;
    s_uncaught = std::uncaught_exception();
    }
    };
    
    bool CheckUncaught::s_checked = false;
    bool CheckUncaught::s_uncaught = false;
    
    void
    checkUncaught(bool insideException)
    {
    bool b4throw = false;
    bool insideCatch = false;
    try {
    CheckUncaught check;
    static_cast<void>(check);
    b4throw = std::uncaught_exception();
    throw 1;
    }
    catch (...) {
    insideCatch = std::uncaught_exception();
    }
    
    bool outsideTry = std::uncaught_exception();
    
    std::cerr << "a) Are we inside an exception? " <<
    insideException << "\n";
    std::cerr << "b) Did we go through the destructor? " <<
    CheckUncaught::s_checked << "\n";
    std::cerr << "c) std::uncaught_exception() before throw should
    be " << insideException << " and is actually " << b4throw <<
    "\n";
    std::cerr << "d) std::uncaught_exception() inside destructor
    should be " << "1 and is actually " << CheckUncaught::s_uncaught
    << "\n";
    std::cerr << "e) std::uncaught_exception() inside catch should
    be " << insideException << " and is actually " << insideCatch <<
    "\n";
    std::cerr << "f) std::uncaught_exception() outside try should be
    " << insideException << " and is actually " << outsideTry <<
    "\n";
    }
    
    class InsideDestructor
    {
    public:
    InsideDestructor()
    {
    checkUncaught(false);
    }
    
    ?InsideDestructor()
    {
    checkUncaught(true);
    }
    };
    }
    
    int
    main()
    {
    try {
    std::cerr << "\nTest 1: Check std::uncaught_exception() is
    false\n";
    uncaught::InsideDestructor check;
    static_cast<void>(check);
    std::cerr << "\nTest 2: Check std::uncaught_exception() is
    true\n";
    throw 1;
    }
    catch (...) {
    std::cerr << "\nTest 3: std::uncaught_exception() should be 0: "
    << std::uncaught_exception() << "\n";
    }
    
    std::cerr << "\nTest 4: std::uncaught_exception() should be 0: "
    << std::uncaught_exception() << "\n";
    
    return 0;
    }
    
    $
    
    ===== ACTUAL OUTPUT:
    $ ./a.out
    
    Test 1: Check std::uncaught_exception() is false
    a) Are we inside an exception? 0
    b) Did we go through the destructor? 1
    c) std::uncaught_exception() before throw should be 0 and is
    actually 0
    d) std::uncaught_exception() inside destructor should be 1 and
    is actually 1
    e) std::uncaught_exception() inside catch should be 0 and is
    actually 0
    f) std::uncaught_exception() outside try should be 0 and is
    actually 0
    
    Test 2: Check std::uncaught_exception() is true
    a) Are we inside an exception? 1
    b) Did we go through the destructor? 1
    c) std::uncaught_exception() before throw should be 1 and is
    actually 1
    d) std::uncaught_exception() inside destructor should be 1 and
    is actually 1
    e) std::uncaught_exception() inside catch should be 1 and is
    actually 0   <------ here
    f) std::uncaught_exception() outside try should be 1 and is
    actually 0       <------ here
    
    Test 3: std::uncaught_exception() should be 0: 0
    
    Test 4: std::uncaught_exception() should be 0: 0
    $
    
    ===== EXPECTED OUTPUT:
    $ ./a.out
    
    Test 1: Check std::uncaught_exception() is false
    a) Are we inside an exception? 0
    b) Did we go through the destructor? 1
    c) std::uncaught_exception() before throw should be 0 and is
    actually 0
    d) std::uncaught_exception() inside destructor should be 1 and
    is actually 1
    e) std::uncaught_exception() inside catch should be 0 and is
    actually 0
    f) std::uncaught_exception() outside try should be 0 and is
    actually 0
    
    Test 2: Check std::uncaught_exception() is true
    a) Are we inside an exception? 1
    b) Did we go through the destructor? 1
    c) std::uncaught_exception() before throw should be 1 and is
    actually 1
    d) std::uncaught_exception() inside destructor should be 1 and
    is actually 1
    e) std::uncaught_exception() inside catch should be 1 and is
    actually 1
    f) std::uncaught_exception() outside try should be 1 and is
    actually 1
    
    Test 3: std::uncaught_exception() should be 0: 0
    
    Test 4: std::uncaught_exception() should be 0: 0
    
    $
    

Local fix

  • N/A
    

Problem summary

  • USERS AFFECTED:
    Users of std::uncaughtExceptionFlag may be affected by this
    issue.
    
    PROBLEM DESCRIPTION:
    The compiler was incorrectly setting the flag to false in some
    catch blocks.
    So it was invalid in nested cases.
    

Problem conclusion

  • The problem has been fixed.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV85614

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    D13

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2016-06-10

  • Closed date

    2016-06-10

  • Last modified date

    2016-06-10

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

    IV84032

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

Fix information

  • Fixed component name

    XL C/C++ FOR AI

  • Fixed component ID

    5725C7200

Applicable component levels

[{"Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"D13"}]

Document Information

Modified date:
07 September 2021