This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fix libstdc++/14026


As diagnosed in the PR, the uncaughtExceptions count goes negative.
And this happens because begin_catch forgets that uncaught exceptions
is not incremented when leaving via rethrow of a nested catch.

Committed.


r~



        * libsupc++/eh_catch.cc (__cxa_begin_catch): Don't adjust 
        uncaughtExceptions during nested catch rethrow.
        * testsuite/18_support/14026.cc: New.

Index: libstdc++-v3/libsupc++/eh_catch.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/eh_catch.cc,v
retrieving revision 1.5
diff -u -p -r1.5 eh_catch.cc
--- libstdc++-v3/libsupc++/eh_catch.cc	24 May 2003 16:22:03 -0000	1.5
+++ libstdc++-v3/libsupc++/eh_catch.cc	8 Feb 2004 17:57:27 -0000
@@ -1,5 +1,5 @@
 // -*- C++ -*- Exception handling routines for catching.
-// Copyright (C) 2001, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -65,10 +65,12 @@ __cxa_begin_catch (void *exc_obj_in)
     // This exception was rethrown from an immediately enclosing region.
     count = -count + 1;
   else
-    count += 1;
+    {
+      count += 1;
+      globals->uncaughtExceptions -= 1;
+    }
   header->handlerCount = count;
 
-  globals->uncaughtExceptions -= 1;
   if (header != prev)
     {
       header->nextException = prev;
Index: libstdc++-v3/testsuite/18_support/14026.cc
===================================================================
RCS file: libstdc++-v3/testsuite/18_support/14026.cc
diff -N libstdc++-v3/testsuite/18_support/14026.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libstdc++-v3/testsuite/18_support/14026.cc	8 Feb 2004 17:57:27 -0000
@@ -0,0 +1,34 @@
+// PR 14026
+// 18.6.4 uncaught_exception
+
+#include <cstdlib>
+#include <exception>
+#include <testsuite_hooks.h>
+
+static void
+no_uncaught ()
+{
+  if (std::uncaught_exception ())
+    abort ();
+}
+
+int
+main ()
+{
+  try
+    {
+      throw 1;
+    }
+  catch (...)
+    {
+      try
+        {
+          throw;
+        }
+      catch (...)
+        {
+          no_uncaught ();
+        }
+    }
+  no_uncaught ();
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]