After using std::rethrow_exception() (and catching the exception), all subsequent calls to std::uncaught_exception() return `true', which is obviously not the way it was meant to work. A simple test case is attached.
Created attachment 33394 [details] A simple test case.
Created attachment 33395 [details] Proposed patch I believe the problem is that std::rethrow_exception() does not update `__cxa_eh_globals::uncaughtExceptions' (which remains zero), while __cxa_begin_catch() decrements it to -1. A proposed patch is attached.
I can confirm this bug. It even occurs with GCC 4.8.2 (on Ubuntu 14.04).
PR61643 shares the root cause with this PR. The behavior of the test case in PR61643 completely agrees with the analysis in Comment 2, and the proposed patch makes the test case in PR61643 work properly. I confirmed that this bug was reproduced with 4.8.4 20140925, 4.9.2 20140924 and 5.0.0 20140928.
*** Bug 61643 has been marked as a duplicate of this bug. ***
I can also confirm this bug (I have a test case with std::async and future, but it internally uses std::rethrow_exception). Known to work: gcc 4.6.3, 4.7.2, 4.8.1 Known to fail: gcc 4.8.2, 4.9.2, clang 3.5.0 So this is a regression.
Confirmed using GCC 5.0.0 20150125 built from source (see below) and 4.7.2 (Debian 4.7.2-5; Debian Wheezy). Tested using the test case in comment 1. Output: $ g++-5-20150125 -std=c++11 -o test62258 test62258.c -Wall && ./test62258 test62258: test62258.c:11: int main(): Assertion `!std::uncaught_exception()' failed. Aborted $ g++-5-20150125 -v Using built-in specs. COLLECT_GCC=g++-5-20150125 COLLECT_LTO_WRAPPER=/home/user/gcc50/bin/../libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /home/user/gcc50build/src-gcc-5-20150125/configure --target=x86_64-unknown-linux-gnu --prefix=/home/user/gcc50build/target-x86_64-unknown-linux-gnu --program-suffix=-5-20150125 --disable-nls --enable-c99 --enable-checking=release --enable-gnu-unique-object --enable-gold --enable-languages=c,c++ --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-linker-build-id --enable-long-long --enable-multiarch --enable-multilib --enable-shared --enable-targets=all --enable-threads=posix --with-system-zlib --with-tune=generic Thread model: posix gcc version 5.0.0 20150125 (experimental) (GCC)
Created attachment 34683 [details] Workaround code For all programmers out there that may encounter this bug, I attach a workaround code. Linking your program with it should make rethrow_exception() usable even if the library on the system is buggy.
A few days ago I submitted a patch for this issue based on Dmitry's patch. It seems as if we can get it in after the 5.0 release. https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00027.html
doko, this fails for me with 4.8.1, and 4.7.4 and 4.8.0 There are no changes between 4.8.1 and 4.8.2 that could have affected this. Are you sure it's a regression?
Author: redi Date: Mon Apr 27 19:44:30 2015 New Revision: 222480 URL: https://gcc.gnu.org/viewcvs?rev=222480&root=gcc&view=rev Log: 2015-04-27 Dmitry Prokoptsev <dprokoptsev@gmail.com> Michael Hanselmann <public@hansmi.ch> PR libstdc++/62258 * libsupc++/eh_ptr.cc (rethrow_exception): Increment count of uncaught exceptions. * testsuite/18_support/exception_ptr/62258.cc: New. Added: trunk/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/libsupc++/eh_ptr.cc
Fixed on trunk so far
doko, I'm still curious if you can verify if you see a regression here or not.
The gcc-4_8-branch is being closed, re-targeting regressions to 4.9.3.
GCC 4.9.3 has been released.
I can confirm it works with 4.8.0 to 4.8.2 but fails since 4.8.3 (just verified using -static-libstdc++ to not fool myself with the installed runtime).
Did this fix make it into the latest GCC 5.2.0 release?
No.
Author: redi Date: Thu Sep 3 15:10:25 2015 New Revision: 227451 URL: https://gcc.gnu.org/viewcvs?rev=227451&root=gcc&view=rev Log: Backport fix for PR libstdc++/62258 from mainline 2015-04-27 Dmitry Prokoptsev <dprokoptsev@gmail.com> Michael Hanselmann <public@hansmi.ch> PR libstdc++/62258 * libsupc++/eh_ptr.cc (rethrow_exception): Increment count of uncaught exceptions. * testsuite/18_support/exception_ptr/62258.cc: New. Added: branches/gcc-5-branch/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc Modified: branches/gcc-5-branch/libstdc++-v3/ChangeLog branches/gcc-5-branch/libstdc++-v3/libsupc++/eh_ptr.cc
Author: redi Date: Thu Sep 3 16:02:07 2015 New Revision: 227456 URL: https://gcc.gnu.org/viewcvs?rev=227456&root=gcc&view=rev Log: Backport fix for PR libstdc++/62258 from mainline 2015-04-27 Dmitry Prokoptsev <dprokoptsev@gmail.com> Michael Hanselmann <public@hansmi.ch> PR libstdc++/62258 * libsupc++/eh_ptr.cc (rethrow_exception): Increment count of uncaught exceptions. * testsuite/18_support/exception_ptr/62258.cc: New. Added: branches/gcc-4_9-branch/libstdc++-v3/testsuite/18_support/exception_ptr/62258.cc Modified: branches/gcc-4_9-branch/libstdc++-v3/ChangeLog branches/gcc-4_9-branch/libstdc++-v3/libsupc++/eh_ptr.cc
Fixed in 4.9.4, 5.3 and 6.0
For the record, the 4.8.3 regression was introduced by r207131 and the 4.7.4 regression by r208991, with the fixes for PR 41174 and PR 59224. The fix should apply cleanly and be safe for the 4.7 and 4.8 branches (although they are closed upstream of course).