diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2015-06-02 15:33:38 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2015-06-02 15:33:38 +0000 |
commit | 89102f0fa96c1d3b53bf289802167fa78baaa83d (patch) | |
tree | 4def1737c86f0993c7cebf597e0b6cc9e53eacf8 | |
parent | 1feab0f95ea0202f95a555a86f5dd60db4a8a5c8 (diff) | |
download | bcm5719-llvm-89102f0fa96c1d3b53bf289802167fa78baaa83d.tar.gz bcm5719-llvm-89102f0fa96c1d3b53bf289802167fa78baaa83d.zip |
Implement uncaught_exceptions() using the newly added hooks in libc++abi, when available
llvm-svn: 238846
-rw-r--r-- | libcxx/include/exception | 4 | ||||
-rw-r--r-- | libcxx/src/exception.cpp | 16 | ||||
-rw-r--r-- | libcxx/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp | 45 | ||||
-rw-r--r-- | libcxx/www/cxx1z_status.html | 2 |
4 files changed, 60 insertions, 7 deletions
diff --git a/libcxx/include/exception b/libcxx/include/exception index ef2b969b742..39d251ec499 100644 --- a/libcxx/include/exception +++ b/libcxx/include/exception @@ -48,7 +48,8 @@ terminate_handler set_terminate(terminate_handler f ) noexcept; 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_terminate() _NOEXCEPT; _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; diff --git a/libcxx/src/exception.cpp b/libcxx/src/exception.cpp index 98b7b441b52..a13a0b9b064 100644 --- a/libcxx/src/exception.cpp +++ b/libcxx/src/exception.cpp @@ -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__ } diff --git a/libcxx/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp b/libcxx/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp new file mode 100644 index 00000000000..1adc904fd5d --- /dev/null +++ b/libcxx/test/std/language.support/support.exception/uncaught/uncaught_exceptions.pass.cpp @@ -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); +} diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index 4ad892e2780..92268925be0 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -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> |