diff mbox

[libstdc++] Add support for std::uncaught_exceptions

Message ID 20150427204029.GQ3618@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely April 27, 2015, 8:40 p.m. UTC
On 13/04/15 02:24 +0300, Ville Voutilainen wrote:
>The patch is a bit large since it does the baseline_symbols regeneration
>and other new-version api-dance.
>Hence attached gzipped.
>
>Tested on Linux x86-64.
>
>2015-04-13  Ville Voutilainen  <ville.voutilainen@gmail.com>
>    Add support for std::uncaught_exceptions.
>    * acinclude.m4: Bump libtool_VERSION.
>    * config/abi/post/x86_64-linux-gnu/baseline_symbols.txt: Regenerate.
>    * config/abi/pre/gnu.ver: Export the new symbol.
>    * configure: Bump libtool_VERSION.
>    * libsupc++/eh_catch.cc(uncaught_exceptions): New.
>    * libsupc++/exception(uncaught_exceptions): Ditto.
>    * testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc: New.
>    * testsuite/util/testsuite_abi.cc: Add 3.4.22 as the latest version.

Tested x86_64-linux and powerpc64le-linux. Committed to trunk.

The baseline_symbols changes aren't needed now and I tweaked the
gnu.ver file slightly.

I also added the feature-test macro recommended by N4440 and changed
the new function to only be declared for -std=gnu++?? and -std=c++1z.
It's useful and easy to provide it for pre-C++17 as an extension.
diff mbox

Patch

commit c37d380f6eea816886147001e0e85932f02b756f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Apr 27 20:46:03 2015 +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.

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index a1e301f..196b4ff 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -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
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 7b82ce8..4ed683c 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -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 {
diff --git a/libstdc++-v3/libsupc++/eh_catch.cc b/libstdc++-v3/libsupc++/eh_catch.cc
index 6302465..723ae56 100644
--- a/libstdc++-v3/libsupc++/eh_catch.cc
+++ b/libstdc++-v3/libsupc++/eh_catch.cc
@@ -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;
+}
diff --git a/libstdc++-v3/libsupc++/exception b/libstdc++-v3/libsupc++/exception
index d6c1855..069b33c 100644
--- a/libstdc++-v3/libsupc++/exception
+++ b/libstdc++-v3/libsupc++/exception
@@ -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
index 0000000..001903e
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc
@@ -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();
+}
diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc
index 116caad..7b76b68 100644
--- a/libstdc++-v3/testsuite/util/testsuite_abi.cc
+++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc
@@ -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");