[libcxx] r238846 - Implement uncaught_exceptions() using the newly added hooks in libc++abi, when available
Marshall Clow
mclow.lists at gmail.com
Tue Jun 2 08:33:39 PDT 2015
Author: marshall
Date: Tue Jun 2 10:33:38 2015
New Revision: 238846
URL: http://llvm.org/viewvc/llvm-project?rev=238846&view=rev
Log:
Implement uncaught_exceptions() using the newly added hooks in libc++abi, when available
Added:
libcxx/trunk/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp
Modified:
libcxx/trunk/include/exception
libcxx/trunk/src/exception.cpp
libcxx/trunk/www/cxx1z_status.html
Modified: libcxx/trunk/include/exception
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/exception?rev=238846&r1=238845&r2=238846&view=diff
==============================================================================
--- libcxx/trunk/include/exception (original)
+++ libcxx/trunk/include/exception Tue Jun 2 10:33:38 2015
@@ -48,7 +48,8 @@ terminate_handler set_terminate(terminat
terminate_handler get_terminate() noexcept;
[[noreturn]] void terminate() noexcept;
-bool uncaught_exception() noexcept;
+bool uncaught_exception() noexcept;
+int uncaught_exceptions() noexcept; // C++17
typedef unspecified exception_ptr;
@@ -115,6 +116,7 @@ _LIBCPP_FUNC_VIS terminate_handler get_t
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT;
_LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT;
+_LIBCPP_FUNC_VIS int uncaught_exceptions() _NOEXCEPT;
class _LIBCPP_TYPE_VIS exception_ptr;
Modified: libcxx/trunk/src/exception.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/exception.cpp?rev=238846&r1=238845&r2=238846&view=diff
==============================================================================
--- libcxx/trunk/src/exception.cpp (original)
+++ libcxx/trunk/src/exception.cpp Tue Jun 2 10:33:38 2015
@@ -105,19 +105,25 @@ terminate() _NOEXCEPT
#endif // !__EMSCRIPTEN__
#endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
+bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
+
#if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__)
-bool uncaught_exception() _NOEXCEPT
+int uncaught_exceptions() _NOEXCEPT
{
#if defined(__APPLE__) || defined(_LIBCPPABI_VERSION)
- // on Darwin, there is a helper function so __cxa_get_globals is private
- return __cxa_uncaught_exception();
+ // on Darwin, there is a helper function so __cxa_get_globals is private
+# if _LIBCPPABI_VERSION > 1101
+ return __cxa_uncaught_exceptions();
+# else
+ return __cxa_uncaught_exception() ? 1 : 0;
+# endif
#else // __APPLE__
# if defined(_MSC_VER) && ! defined(__clang__)
- _LIBCPP_WARNING("uncaught_exception not yet implemented")
+ _LIBCPP_WARNING("uncaught_exceptions not yet implemented")
# else
# warning uncaught_exception not yet implemented
# endif
- fprintf(stderr, "uncaught_exception not yet implemented\n");
+ fprintf(stderr, "uncaught_exceptions not yet implemented\n");
::abort();
#endif // __APPLE__
}
Added: libcxx/trunk/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp?rev=238846&view=auto
==============================================================================
--- libcxx/trunk/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp (added)
+++ libcxx/trunk/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp Tue Jun 2 10:33:38 2015
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test uncaught_exceptions
+
+#include <exception>
+#include <cassert>
+
+struct A
+{
+ ~A()
+ {
+ assert(std::uncaught_exceptions() > 0);
+ }
+};
+
+struct B
+{
+ B()
+ {
+ // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#475
+ assert(std::uncaught_exceptions() == 0);
+ }
+};
+
+int main()
+{
+ try
+ {
+ A a;
+ assert(std::uncaught_exceptions() == 0);
+ throw B();
+ }
+ catch (...)
+ {
+ assert(std::uncaught_exception() == 0);
+ }
+ assert(std::uncaught_exceptions() == 0);
+}
Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=238846&r1=238845&r2=238846&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Tue Jun 2 10:33:38 2015
@@ -57,7 +57,7 @@
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4169">N4169</a></td><td>LWG</td></td><td>A proposal to add invoke function template</td><td>Urbana</td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4190">N4190</a></td></td><td>LWG</td><td>Removing auto_ptr, random_shuffle(), And Old <functional> Stuff.</td><td>Urbana</td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4258">N4258</a></td><td>LWG</td></td><td>Cleaning-up noexcept in the Library.</td><td>Urbana</td><td></td><td></td></tr>
- <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4259">N4259</a></td><td>CWG</td></td><td>Wording for std::uncaught_exceptions</td><td>Urbana</td><td></td><td></td></tr>
+ <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4259">N4259</a></td><td>CWG</td></td><td>Wording for std::uncaught_exceptions</td><td>Urbana</td><td>Complete</td><td>3.7</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4277">N4277</a></td><td>LWG</td></td><td>TriviallyCopyable <code>reference_wrapper</code>.</td><td>Urbana</td><td>Complete</td><td>3.2</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4279">N4279</a></td><td>LWG</td></td><td>Improved insertion interface for unique-key maps.</td><td>Urbana</td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4280">N4280</a></td><td>LWG</td></td><td>Non-member size() and more</td><td>Urbana</td><td>Complete</td><td>3.6</td></tr>
More information about the cfe-commits
mailing list