The description of uncaught_exception() throw() function states (18.6.4): Returns: true after completing evaluation of a throw-expression until either completing initialization of the exception-declaration in the matching handler or entering unexpected() due to the throw; or after entering terminate() for any reason other than an explicit call to terminate(). Apart from an explicit call to terminate() from the user's code, terminate() is called in the following situations (15.5.1): 1. When the exception handling mechanism, after completing evaluation of the expression to be thrown but before the exception is caught, calls a user function that exits via an uncaught exception. 2. When the exception handling mechanism cannot find a handler for a thrown exception. 3. When the destruction of an object during stack unwinding exits using an exception. 4. When construction or destruction of a non-local object with static storage duration exits using an exception. 5. When execution of a function registered with atexit exits using an exception. 6. When a throw-expression with no operand attempts to rethrow an exception and no exception is being handled. 7. When unexpected throws an exception which is not allowed by the previously violated exception specification, and std::bad_exception is not included in that exception-specification. However std::uncaught_exception called within a terminate_handler returns false in the cases 2,4,5,7 and true in the other cases (terminate_handler is specified using std::set_terminate()). The attached examples demonstrate the above 7 situations when terminate() is called "implicitly" and display the return value of std::uncaught_exception(). For example, reproducing situation 2: andrew@Ubuntu:/mnt/hgfs/shared/temp/test$ g++ -Wall test2.cpp && ./a.out Exception will be thrown and it won't be catched. This situation meets the following condition when terminate should be called: 2.When the exception handling mechanism cannot find a handler for a thrown exception. Inside terminate_handler uncaught_exception() returns *false*. terminate called after throwing an instance of 'char const*' Aborted (core dumped) andrew@Ubuntu:/mnt/hgfs/shared/temp/test$ g++ --version g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu4) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Created attachment 16292 [details] test.tar Reproduce situations when terminate is called implicitly.
Note this is a libsupc++ issue, we don't have a specific Bugzilla component, but as a matter of fact the code has been mostly implemented and maintained by different people than the libstdc++ maintainers... I'm afraid it will take some time to review the issue and in case work on the code.
Richard, any chance you can look a bit into this? Many thanks in advance.
I'm trusting Jon here: in the audi trail of PR41174 he mentioned that this issue depends on the resolution of Core issue 475 (currently in drafting): http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#475
Suspending, waiting for [Ready].
The status is now [Ready], unsuspending.
Created attachment 24538 [details] Exhibits uncaught return values
I just attached a testcase which seems likely related to this bug. Tested with g++ (GCC) 4.6.0 20110603 on x86_64 linux.