I'm not sure whether to call this a new bug or not, because the error is very
similar to the existing bug 42159.  However, the system I am on does not crash
for the code listed in that bug report.  Also, the comments for that bug seem
to be indicating that the bug is specific to Snow Leopard, while the crash I am
reporting here is happening on a Leopard OS.

My distilled program that is producing a crash rather than catching and exiting
gracefully is similarly simple to the code in 42159:

#include <iostream> // The abort persists if all ios stuff is removed.

class A

    inline ~A() {} // If this is removed, catch works (Just like for 42159)

    inline void throw_int() const { throw int(1); }


class B

    inline void throw_int() // If this is in main, catch works.
        A a;


int main()
    std::cout<<"Before try block"<<std::endl;
    try {
        B b;
        std::cout<<"Before throw_int."<<std::endl;
        std::cout<<"After throw_int. Should have thrown."<<std::endl;
    } catch (int) {
        std::cout<<"Correctly thrown and caught. "<<std::endl;
    std::cout<<"After try block."<<std::endl;

    return 0;

With g++ 4.4.4 (and others), I get the correct output:

Before try block
Before throw_int.
Correctly thrown and caught. 
After try block.

With g++ 4.5.0, I get:

Before try block
Before throw_int.
Abort trap

For completeness, gdb produces the following information:

(gdb) run
Before try block
Before throw_int.

Program received signal SIGABRT, Aborted.
0x941b1e42 in __kill ()
(gdb) bt
#0  0x941b1e42 in __kill ()
#1  0x941b1e34 in kill$UNIX2003 ()
#2  0x9422423a in raise ()
#3  0x94230679 in abort ()
#4  0x92c0aa2a in _Unwind_Resume ()
#5  0x00001e60 in B::throw_int ()
#6  0x00001c9e in main ()

My system is Mac OS X version 10.5.8 (Leopard), running on a 2.2 GHz Intel Core
2 Duo MacBook.

I am using the current latest fink version of gcc45: 4.5.0-1000.

$ g++-4 --version
g++-4 (GCC) 4.5.0
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

           Summary: throw not being caught
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: michael at jarvis dot net


Reply via email to