Index: src/exception.cpp =================================================================== --- src/exception.cpp +++ src/exception.cpp @@ -29,6 +29,8 @@ #define __terminate_handler __cxxabiapple::__cxa_terminate_handler #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler #endif // _LIBCPPABI_VERSION +#elif defined(_LIBCPP_MSVCRT) + #include #elif defined(LIBCXXRT) || __has_include() #include using namespace __cxxabiv1; @@ -49,34 +51,54 @@ unexpected_handler set_unexpected(unexpected_handler func) _NOEXCEPT { +#ifndef _LIBCPP_MSVCRT return __sync_lock_test_and_set(&__unexpected_handler, func); +#else + return ::set_unexpected(func); +#endif // !_LIBCPP_MSVCRT } unexpected_handler get_unexpected() _NOEXCEPT { +#ifndef _LIBCPP_MSVCRT return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); +#else + return ::_get_unexpected(); +#endif // !_LIBCPP_MSVCRT } _LIBCPP_NORETURN void unexpected() { +#ifndef _LIBCPP_MSVCRT (*get_unexpected())(); // unexpected handler should not return terminate(); +#else + return ::unexpected(); +#endif // !_LIBCPP_MSVCRT } terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { +#ifndef _LIBCPP_MSVCRT return __sync_lock_test_and_set(&__terminate_handler, func); +#else + return ::set_terminate(func); +#endif // !_LIBCPP_MSVCRT } terminate_handler get_terminate() _NOEXCEPT { +#ifndef _LIBCPP_MSVCRT return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0); +#else + return ::_get_terminate(); +#endif // !_LIBCPP_MSVCRT } #ifndef __EMSCRIPTEN__ // We provide this in JS @@ -84,6 +106,7 @@ void terminate() _NOEXCEPT { +#ifndef _LIBCPP_MSVCRT #ifndef _LIBCPP_NO_EXCEPTIONS try { @@ -101,9 +124,12 @@ ::abort(); } #endif // _LIBCPP_NO_EXCEPTIONS +#else + return ::terminate(); +#endif // !_LIBCPP_MSVCRT } #endif // !__EMSCRIPTEN__ -#endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) +#endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) #if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__) bool uncaught_exception() _NOEXCEPT @@ -111,7 +137,9 @@ #if defined(__APPLE__) || defined(_LIBCPPABI_VERSION) // on Darwin, there is a helper function so __cxa_get_globals is private return __cxa_uncaught_exception(); -#else // __APPLE__ +#elif defined(_LIBCPP_MSVCRT) + return ::__uncaught_exception(); +#else # if defined(_MSC_VER) && ! defined(__clang__) _LIBCPP_WARNING("uncaught_exception not yet implemented") # else @@ -135,7 +163,7 @@ } #endif // _LIBCPPABI_VERSION -#endif //LIBCXXRT +#endif // !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__) #if !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) bad_exception::~bad_exception() _NOEXCEPT Index: test/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp =================================================================== --- test/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp +++ test/depr/exception.unexpected/set.unexpected/get_unexpected.pass.cpp @@ -7,6 +7,9 @@ // //===----------------------------------------------------------------------===// +// msvcrt default unexpected handler is null +// XFAIL: win32 + // test get_unexpected #include