Add support for std::uncaught_exceptions.
authorVille Voutilainen <ville.voutilainen@gmail.com>
Mon, 27 Apr 2015 20:40:29 +0000 (23:40 +0300)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 27 Apr 2015 20:40:29 +0000 (21:40 +0100)
2015-04-27  Ville Voutilainen  <ville.voutilainen@gmail.com>

Add support for std::uncaught_exceptions.
* acinclude.m4: Bump libtool_VERSION.
* config/abi/pre/gnu.ver: Export the new symbol.
* configure: Regenerate.
* libsupc++/eh_catch.cc (uncaught_exceptions): New.
* libsupc++/exception (uncaught_exceptions): New.
* testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc: New.
* testsuite/util/testsuite_abi.cc: Add 3.4.22 as the latest version.

From-SVN: r222482

libstdc++-v3/ChangeLog
libstdc++-v3/acinclude.m4
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/libsupc++/eh_catch.cc
libstdc++-v3/libsupc++/exception
libstdc++-v3/testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc [new file with mode: 0644]
libstdc++-v3/testsuite/util/testsuite_abi.cc

index 3402ee81ab6288d3e974137672b60d745721a236..c67471048901a8b3e37f63ac623ea1e36cf9f730 100644 (file)
@@ -1,3 +1,14 @@
+2015-04-27  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Add support for std::uncaught_exceptions.
+       * acinclude.m4: Bump libtool_VERSION.
+       * config/abi/pre/gnu.ver: Export the new symbol.
+       * configure: Regenerate.
+       * libsupc++/eh_catch.cc (uncaught_exceptions): New.
+       * libsupc++/exception (uncaught_exceptions): New.
+       * testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc: New.
+       * testsuite/util/testsuite_abi.cc: Add 3.4.22 as the latest version.
+
 2015-04-27  Dmitry Prokoptsev  <dprokoptsev@gmail.com>
            Michael Hanselmann  <public@hansmi.ch>
 
index a1e301fdaa9bad7347aeaf693cc1357689c053c4..196b4ff1b37898cb76bac2e31d56775450bba89a 100644 (file)
@@ -3383,7 +3383,7 @@ changequote([,])dnl
 fi
 
 # For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=6:21:0
+libtool_VERSION=6:22:0
 
 # Everything parsed; figure out what files and settings to use.
 case $enable_symvers in
index 7b82ce88ae409d2400b2db1efbde4f05d76d1909..4ed683cf36e5d7f0631e8859c0dffd7877d406af 100644 (file)
@@ -178,7 +178,6 @@ GLIBCXX_3.4 {
 #     std::[A-Zu-z]*;
 #     std::underflow_error::u*;
 #     std::underflow_error::~u*;
-      std::uncaught_exception*;
       std::unexpected*;
       std::[A-Zv-z]*;
       std::_List_node_base::hook*;
@@ -1024,6 +1023,9 @@ GLIBCXX_3.4 {
     _ZNSt6locale5_Impl19_M_replace_categoryEPKS0_PKPKNS_2idE;
     _ZNSt6locale5_Impl21_M_replace_categoriesEPKS0_i;
 
+    # std::uncaught_exception()
+    _ZSt18uncaught_exceptionv;
+
   # DO NOT DELETE THIS LINE.  Port-specific symbols, if any, will be here.
 
   local:
@@ -1860,6 +1862,12 @@ GLIBCXX_3.4.21 {
 
 } GLIBCXX_3.4.20;
 
+GLIBCXX_3.4.22 {
+
+    # std::uncaught_exception()
+    _ZSt19uncaught_exceptionsv;
+
+} GLIBCXX_3.4.21;
 
 # Symbols in the support library (libsupc++) have their own tag.
 CXXABI_1.3 {
index 6302465d5038df56db3e39d33ff93ab4cf295485..723ae56723df286c3d421037847e88d0ad089b52 100644 (file)
@@ -139,3 +139,10 @@ std::uncaught_exception() throw()
   __cxa_eh_globals *globals = __cxa_get_globals ();
   return globals->uncaughtExceptions != 0;
 }
+
+int
+std::uncaught_exceptions() throw()
+{
+  __cxa_eh_globals *globals = __cxa_get_globals ();
+  return globals->uncaughtExceptions;
+}
index d6c18553b2f836126f28fbd1c7d811f31749ae9f..069b33cd8dabf80d1817ce3943ed4acceeec1774 100644 (file)
@@ -126,6 +126,11 @@ namespace std
    */
   bool uncaught_exception() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
 
+#if !defined(__STRICT_ANSI__) || __cplusplus > 201402L
+#define __cpp_lib_uncaught_exceptions 201411
+  int uncaught_exceptions() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__pure__));
+#endif
+
   // @} group exceptions
 } // namespace std
 
diff --git a/libstdc++-v3/testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc b/libstdc++-v3/testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc
new file mode 100644 (file)
index 0000000..001903e
--- /dev/null
@@ -0,0 +1,162 @@
+// Copyright (C) 2015 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+
+#include <cassert>
+#include <exception>
+#include <testsuite_hooks.h>
+
+struct UncaughtVerifier
+{
+  int expected_count_ = 0;
+  UncaughtVerifier(int expected_count) : expected_count_(expected_count) {}
+  ~UncaughtVerifier()
+  {
+    VERIFY(std::uncaught_exceptions() == expected_count_);
+  }
+};
+
+struct Transaction
+{
+  int initial_count_;
+  bool& result_;
+  Transaction(bool& result)
+  : initial_count_(std::uncaught_exceptions()),
+    result_(result) {}
+  ~Transaction()
+  {
+    if (std::uncaught_exceptions() != initial_count_) {
+      result_ = false;
+    }
+  }
+};
+
+void test01()
+{
+  try {
+    UncaughtVerifier uv{0};
+  } catch (...) {
+    UncaughtVerifier uv{0};
+  }
+}
+
+void test02()
+{
+  try {
+    UncaughtVerifier uv{1};
+    throw 0;
+  } catch (...) {
+    UncaughtVerifier uv{0};
+  }
+}
+
+void test03()
+{
+  try {
+    struct Wrap
+    {
+      UncaughtVerifier uv_{1};
+      ~Wrap() {try {UncaughtVerifier uv2{2}; throw 0;} catch(...) {}}
+    };
+    Wrap w;
+    throw 0;
+  } catch (...) {
+    UncaughtVerifier uv{0};
+  }
+}
+
+void test04()
+{
+  bool result = true;
+  try {
+    Transaction t{result};
+  } catch(...) {
+  }
+  VERIFY(result);
+}
+
+void test05()
+{
+  bool result = true;
+  try {
+    Transaction t{result};
+    throw 0;
+  } catch(...) {
+  }
+  VERIFY(!result);
+}
+
+void test06()
+{
+  bool result = true;
+  bool result2 = true;
+  try {
+    struct Wrap
+    {
+      bool& result_;
+      Wrap(bool& result) : result_(result) {}
+      ~Wrap()
+      {
+        Transaction t{result_};
+      }
+    };
+    Transaction t{result};
+    Wrap w{result2};
+    throw 0;
+  } catch(...) {
+  }
+  VERIFY(!result);
+  VERIFY(result2);
+}
+
+void test07()
+{
+  bool result = true;
+  bool result2 = true;
+  try {
+    struct Wrap
+    {
+      bool& result_;
+      Wrap(bool& result) : result_(result) {}
+      ~Wrap()
+      {
+        try {
+          Transaction t{result_};
+          throw 0;
+        } catch(...) {}
+      }
+    };
+    Transaction t{result};
+    Wrap w{result2};
+    throw 0;
+  } catch(...) {
+  }
+  VERIFY(!result);
+  VERIFY(!result2);
+}
+
+int main()
+{
+  test01();
+  test02();
+  test03();
+  test04();
+  test05();
+  test06();
+  test07();
+}
index 116caad5a12f7158730d44252f0e57e1b717f33a..7b76b688155f23750f910bd1b9add7c60be8a354 100644 (file)
@@ -201,6 +201,7 @@ check_version(symbol& test, bool added)
       known_versions.push_back("GLIBCXX_3.4.19");
       known_versions.push_back("GLIBCXX_3.4.20");
       known_versions.push_back("GLIBCXX_3.4.21");
+      known_versions.push_back("GLIBCXX_3.4.22");
       known_versions.push_back("GLIBCXX_LDBL_3.4.21");
       known_versions.push_back("CXXABI_1.3");
       known_versions.push_back("CXXABI_LDBL_1.3");
@@ -230,7 +231,7 @@ check_version(symbol& test, bool added)
        test.version_status = symbol::incompatible;
 
       // Check that added symbols are added in the latest pre-release version.
-      bool latestp = (test.version_name == "GLIBCXX_3.4.21"
+      bool latestp = (test.version_name == "GLIBCXX_3.4.22"
                     || test.version_name == "CXXABI_1.3.9"
                     || test.version_name == "CXXABI_FLOAT128"
                     || test.version_name == "CXXABI_TM_1");