IV46854: EXCEPTION THROWN CAUSES DESTRUCTOR TO SKIP

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • The below test case shows that throwing of exceptions causes
    destructors to be skipped, and creates all sorts of strange
    behavior down the chain with xlC V11.1 and V12.1. xlC v10.1
    works.
    
    
    ===== TESTCASE:
    $cat test.cpp
    #include <iostream>
    class MyClassEmptyDestructor
    {
        bool v1;
    public:
        MyClassEmptyDestructor()
         : v1(false)
        {
            // Bug exposed whether constructor is empty or not
            /// std::cout << "MyClass constructor" << std::endl;
        }
    
        ~MyClassEmptyDestructor()
        {
            // Note: must be empty: if following is activated, all
    destructors are called
            ///std::cout << "MyClass destructor" << std::endl;
        }
    };
    
    class Canary
    {
        unsigned int m_canary;
    
    public:
        // Note: a parameter is required here (doesn't need to be
    used).
        Canary(unsigned int id) : m_canary(id)
        {
            std::cout << "Canary entering " << m_canary <<
    std::endl;
        }
    
        ~Canary()
        {
            // Sing - note singing is mandatory
            std::cout << "Canary exiting " << m_canary << std::endl;
        }
    };
    
    void test_and_throw(bool exp)
    {
        // None of these destructors will be called
        Canary canary1(1);
        Canary canary2(2);
        Canary canary3(3);
        Canary canary4(4);
    
        if(exp) {
            // Must have class with empty destructor here
            // Even though execution path does not reach.
            MyClassEmptyDestructor myclass;
            return;  // This return is also essential for the bug
    to show
        }
    
        // These destructors will be called
        Canary canary5(5);
        Canary canary6(6);
    
        throw "Naked Exception";  /// This throw is essential for
    the bug to show
    }
    
    int main(int argc, char **argv)
    {
        try {
            std::cout << "Calling test_and_throw" << std::endl;
            test_and_throw(false);
            std::cout << "After test_and_throw" << std::endl;
        }
        catch (...) {
            std::cout << "Caught exception" << std::endl;
        }
    }
    
    xlC_r test.cpp
    $./a.out
    Calling test_and_throw
    Canary entering 1
    Canary entering 2
    Canary entering 3
    Canary entering 4
    Canary entering 5
    Canary entering 6
    Canary exiting 6
    Canary exiting 5
    Caught exception
    
    Expected Output:
    xlC_r test.cpp
    $./a.out
    Calling test_and_throw
    Canary entering 1
    Canary entering 2
    Canary entering 3
    Canary entering 4
    Canary entering 5
    Canary entering 6
    Canary exiting 6
    Canary exiting 5
    Canary exiting 4
    Canary exiting 3
    Canary exiting 2
    Canary exiting 1
    Caught exception
    

Local fix

  • Do not make the destructor empty.
    

Problem summary

  • PROBLEM DESCRIPTION: Destructors were not being called due to
    error in state tables.
    
    USERS AFFECTED: All users constructing classes within or after
    a throw / exception handling
    

Problem conclusion

  • The issue has been solved. Apply applicable service.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV46854

  • Reported component name

    XL C/C++ AIX

  • Reported component ID

    5724X1300

  • Reported release

    B10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2013-08-09

  • Closed date

    2013-11-18

  • Last modified date

    2013-11-18

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

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

    LI77709 IV53340

Fix information

  • Fixed component name

    XL C/C++ AIX

  • Fixed component ID

    5724X1300

Applicable component levels

  • RB10 PSY U863140

       UP C



Rate this page:

(0 users)Average rating

Document information


More support for:

XL C/C++ for AIX

Software version:

11.1

Reference #:

IV46854

Modified date:

2013-11-18

Translate my page

Machine Translation

Content navigation