This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
The following code shows the problem: #include <iostream> int main() { try { throw 1; } catch (...) { try { throw; } catch (...) { std::cout << std::uncaught_exception() << std::endl; } } std::cout << std::uncaught_exception() << std::endl; } The program prints: 1 1 The expected output is: 0 0 Some detail: std::uncaught_exception() uses a variable (uncaughtExceptions), that counts the number of uncaught exceptions. The value of this variable is -1 at the two print statements. I guess, this variable is incremented each time an exception is thrown and decremented each time an exception is caught. I also guess, that in the above program, the variable is possible not incremented at the rethrow statement.
Okay, the command line and compiler output is missing: Here it is. The following program (same as in original description) does not work with: /tmp > g++-3.2 -v -Wall bug-ex.cc -o bug-ex Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.3/specs Configured with: ../src/configure -v --enable-languages=c,c++,f77,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-objc-gc i386-linux Thread model: posix gcc version 3.2.3 (Debian) /usr/lib/gcc-lib/i386-linux/3.2.3/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ bug-ex.cc -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -quiet -dumpbase bug-ex.cc -Wall -version -o /tmp/ccXJp6ZE.s GNU CPP version 3.2.3 (Debian) (cpplib) (i386 Linux/ELF) GNU C++ version 3.2.3 (Debian) (i386-linux) compiled by GNU C version 3.2.3 (Debian). ignoring nonexistent directory "/usr/i386-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/3.2 /usr/include/c++/3.2/i386-linux /usr/include/c++/3.2/backward /usr/local/include /usr/lib/gcc-lib/i386-linux/3.2.3/include /usr/include End of search list. as -V -Qy -o /tmp/cc7xIPyK.o /tmp/ccXJp6ZE.s GNU assembler version 2.14.90.0.7 (i386-linux) using BFD version 2.14.90.0.7 20031029 Debian GNU/Linux /usr/lib/gcc-lib/i386-linux/3.2.3/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o bug-ex /usr/lib/gcc-lib/i386-linux/3.2.3/../../../crt1.o /usr/lib/gcc-lib/i386-linux/3.2.3/../../../crti.o /usr/lib/gcc-lib/i386-linux/3.2.3/crtbegin.o -L/usr/lib/gcc-lib/i386-linux/3.2.3 -L/usr/lib/gcc-lib/i386-linux/3.2.3/../../.. /tmp/cc7xIPyK.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc-lib/i386-linux/3.2.3/crtend.o /usr/lib/gcc-lib/i386-linux/3.2.3/../../../crtn.o #include <iostream> int main() { try { throw 1; } catch (...) { try { throw; } catch (...) { std::cout << std::uncaught_exception() << std::endl; } } std::cout << std::uncaught_exception() << std::endl; } Wrong output: 1 1 Correct output: 0 0 Same behaviour with gcc 3.3.3 (Debian): /tmp > g++-3.3 -v -Wall bug-ex.cc -o bug-ex Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux Thread model: posix gcc version 3.3.3 20040125 (prerelease) (Debian) /usr/lib/gcc-lib/i486-linux/3.3.3/cc1plus -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -D_GNU_SOURCE bug-ex.cc -D__GNUG__=3 -quiet -dumpbase bug-ex.cc -auxbase bug-ex -Wall -version -o /tmp/ccSG2PSd.s GNU C++ version 3.3.3 20040125 (prerelease) (Debian) (i486-linux) compiled by GNU C version 3.3.3 20040125 (prerelease) (Debian). GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64471 ignoring nonexistent directory "/usr/i486-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/3.3 /usr/include/c++/3.3/i486-linux /usr/include/c++/3.3/backward /usr/local/include /usr/lib/gcc-lib/i486-linux/3.3.3/include /usr/include End of search list. as -V -Qy -o /tmp/ccQNDRUV.o /tmp/ccSG2PSd.s GNU assembler version 2.14.90.0.7 (i386-linux) using BFD version 2.14.90.0.7 20031029 Debian GNU/Linux /usr/lib/gcc-lib/i486-linux/3.3.3/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o bug-ex /usr/lib/gcc-lib/i486-linux/3.3.3/../../../crt1.o /usr/lib/gcc-lib/i486-linux/3.3.3/../../../crti.o /usr/lib/gcc-lib/i486-linux/3.3.3/crtbegin.o -L/usr/lib/gcc-lib/i486-linux/3.3.3 -L/usr/lib/gcc-lib/i486-linux/3.3.3/../../.. /tmp/ccQNDRUV.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc-lib/i486-linux/3.3.3/crtend.o /usr/lib/gcc-lib/i486-linux/3.3.3/../../../crtn.o
Confirmed. I don't know if this is a C++ or libstdc++ problem, though. W.
Almost sure that this is a libstdc++ bug.
Yes, it's a libstdc++ bug. It looks like uncaught_exception() has always (3.0.0 ->) been buggy in case of rethrow: globals->uncaughtExceptions (which is an unsigned int) is not increased from 0, then when is decreased in the catch block becomes (unsigned int)(-1) and uncaught_exception, which is globals->uncaughtExceptions != 0, returns 1. Ouch!
If I'm not mistaken you are the original author of the new exception handling code. Can you possibly have a look at this bug and 10606? Thanks!
Subject: Bug 14026 CVSROOT: /cvs/gcc Module name: gcc Changes by: rth@gcc.gnu.org 2004-02-08 18:01:23 Modified files: libstdc++-v3 : ChangeLog libstdc++-v3/libsupc++: eh_catch.cc Added files: libstdc++-v3/testsuite/18_support: 14026.cc Log message: PR libstdc++/14026 * libsupc++/eh_catch.cc (__cxa_begin_catch): Don't adjust uncaughtExceptions during nested catch rethrow. * testsuite/18_support/14026.cc: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2315&r2=1.2316 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/libsupc++/eh_catch.cc.diff?cvsroot=gcc&r1=1.5&r2=1.6 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/18_support/14026.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 14026 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: rth@gcc.gnu.org 2004-02-08 18:11:23 Modified files: libstdc++-v3 : ChangeLog libstdc++-v3/libsupc++: eh_catch.cc Added files: libstdc++-v3/testsuite/18_support: 14026.cc Log message: PR libstdc++/14026 * libsupc++/eh_catch.cc (__cxa_begin_catch): Don't adjust uncaughtExceptions during nested catch rethrow. * testsuite/18_support/14026.cc: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2224.2.26&r2=1.2224.2.27 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/libsupc++/eh_catch.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.5&r2=1.5.16.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/18_support/14026.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/ml/gcc-patches/2004-02/msg00730.html
Subject: Bug 14026 CVSROOT: /cvs/gcc Module name: gcc Branch: hammer-3_3-branch Changes by: paolo@gcc.gnu.org 2004-08-16 15:58:45 Modified files: libstdc++-v3 : ChangeLog.hammer libstdc++-v3/libsupc++: eh_catch.cc Log message: 2004-08-16 Richard Henderson <rth@redhat.com> PR libstdc++/14026 * libsupc++/eh_catch.cc (__cxa_begin_catch): Don't adjust uncaughtExceptions during nested catch rethrow. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.39&r2=1.1.2.40 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/libsupc++/eh_catch.cc.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.3.32.1&r2=1.3.32.2