2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
2021-11-18 05:25:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_EXCEPTION
|
|
|
|
#define _LIBCPP_EXCEPTION
|
|
|
|
|
|
|
|
/*
|
|
|
|
exception synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
class exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
exception() noexcept;
|
|
|
|
exception(const exception&) noexcept;
|
|
|
|
exception& operator=(const exception&) noexcept;
|
|
|
|
virtual ~exception() noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class bad_exception
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_exception() noexcept;
|
|
|
|
bad_exception(const bad_exception&) noexcept;
|
|
|
|
bad_exception& operator=(const bad_exception&) noexcept;
|
|
|
|
virtual ~bad_exception() noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*unexpected_handler)();
|
2011-05-27 02:23:59 +08:00
|
|
|
unexpected_handler set_unexpected(unexpected_handler f ) noexcept;
|
|
|
|
unexpected_handler get_unexpected() noexcept;
|
|
|
|
[[noreturn]] void unexpected();
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
typedef void (*terminate_handler)();
|
2011-05-27 02:23:59 +08:00
|
|
|
terminate_handler set_terminate(terminate_handler f ) noexcept;
|
|
|
|
terminate_handler get_terminate() noexcept;
|
|
|
|
[[noreturn]] void terminate() noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2015-06-02 23:33:38 +08:00
|
|
|
bool uncaught_exception() noexcept;
|
|
|
|
int uncaught_exceptions() noexcept; // C++17
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
typedef unspecified exception_ptr;
|
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
exception_ptr current_exception() noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
void rethrow_exception [[noreturn]] (exception_ptr p);
|
2011-05-27 02:23:59 +08:00
|
|
|
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
class nested_exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
nested_exception() noexcept;
|
|
|
|
nested_exception(const nested_exception&) noexcept = default;
|
|
|
|
nested_exception& operator=(const nested_exception&) noexcept = default;
|
2010-05-12 03:42:16 +08:00
|
|
|
virtual ~nested_exception() = default;
|
|
|
|
|
|
|
|
// access functions
|
2011-05-27 02:23:59 +08:00
|
|
|
[[noreturn]] void rethrow_nested() const;
|
|
|
|
exception_ptr nested_ptr() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
template <class T> [[noreturn]] void throw_with_nested(T&& t);
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class E> void rethrow_if_nested(const E& e);
|
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-03-26 00:55:36 +08:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2020-11-05 04:01:25 +08:00
|
|
|
#include <__availability>
|
2021-05-19 23:57:04 +08:00
|
|
|
#include <__config>
|
2021-04-15 01:59:03 +08:00
|
|
|
#include <__memory/addressof.h>
|
2010-05-12 03:42:16 +08:00
|
|
|
#include <cstddef>
|
2016-12-03 11:22:11 +08:00
|
|
|
#include <cstdlib>
|
2010-05-28 01:06:52 +08:00
|
|
|
#include <type_traits>
|
2018-09-13 03:41:40 +08:00
|
|
|
#include <version>
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2019-03-05 09:57:01 +08:00
|
|
|
#if defined(_LIBCPP_ABI_VCRUNTIME)
|
2017-02-10 16:57:35 +08:00
|
|
|
#include <vcruntime_exception.h>
|
|
|
|
#endif
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
namespace std // purposefully not using versioning namespace
|
|
|
|
{
|
|
|
|
|
2019-03-05 09:57:01 +08:00
|
|
|
#if !defined(_LIBCPP_ABI_VCRUNTIME)
|
2010-05-12 03:42:16 +08:00
|
|
|
class _LIBCPP_EXCEPTION_ABI exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {}
|
2020-03-14 02:36:26 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception(const exception&) _NOEXCEPT = default;
|
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
virtual ~exception() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_exception
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY bad_exception() _NOEXCEPT {}
|
|
|
|
virtual ~bad_exception() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
2019-03-05 09:57:01 +08:00
|
|
|
#endif // !_LIBCPP_ABI_VCRUNTIME
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-02-17 11:25:08 +08:00
|
|
|
#if _LIBCPP_STD_VER <= 14 \
|
|
|
|
|| defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \
|
|
|
|
|| defined(_LIBCPP_BUILDING_LIBRARY)
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef void (*unexpected_handler)();
|
2013-03-07 07:30:19 +08:00
|
|
|
_LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT;
|
|
|
|
_LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT;
|
|
|
|
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected();
|
2017-02-17 11:25:08 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
typedef void (*terminate_handler)();
|
2013-03-07 07:30:19 +08:00
|
|
|
_LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
|
|
|
|
_LIBCPP_FUNC_VIS terminate_handler get_terminate() _NOEXCEPT;
|
|
|
|
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
_LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT;
|
2017-05-05 01:08:54 +08:00
|
|
|
_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS int uncaught_exceptions() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
class _LIBCPP_TYPE_VIS exception_ptr;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT;
|
|
|
|
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
#ifndef _LIBCPP_ABI_MICROSOFT
|
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
class _LIBCPP_TYPE_VIS exception_ptr
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
void* __ptr_;
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
exception_ptr(const exception_ptr&) _NOEXCEPT;
|
|
|
|
exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
|
|
|
|
~exception_ptr() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-06-16 00:57:54 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY explicit operator bool() const _NOEXCEPT
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
{return __ptr_ != nullptr;}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 05:28:23 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
2011-05-27 02:23:59 +08:00
|
|
|
bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.__ptr_ == __y.__ptr_;}
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
|
2010-09-22 05:28:23 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
2011-05-27 02:23:59 +08:00
|
|
|
bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{return !(__x == __y);}
|
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
friend _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT;
|
|
|
|
friend _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr);
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template<class _Ep>
|
2018-11-22 01:00:52 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr
|
2011-11-30 02:15:50 +08:00
|
|
|
make_exception_ptr(_Ep __e) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
throw __e;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return current_exception();
|
|
|
|
}
|
2016-12-03 11:22:11 +08:00
|
|
|
#else
|
2016-12-24 07:37:52 +08:00
|
|
|
((void)__e);
|
2016-12-03 11:22:11 +08:00
|
|
|
_VSTD::abort();
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
#else // _LIBCPP_ABI_MICROSOFT
|
|
|
|
|
|
|
|
class _LIBCPP_TYPE_VIS exception_ptr
|
|
|
|
{
|
2022-02-15 01:52:28 +08:00
|
|
|
_LIBCPP_DIAGNOSTIC_PUSH
|
|
|
|
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
void* __ptr1_;
|
|
|
|
void* __ptr2_;
|
2022-02-15 01:52:28 +08:00
|
|
|
_LIBCPP_DIAGNOSTIC_POP
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
public:
|
|
|
|
exception_ptr() _NOEXCEPT;
|
|
|
|
exception_ptr(nullptr_t) _NOEXCEPT;
|
|
|
|
exception_ptr(const exception_ptr& __other) _NOEXCEPT;
|
|
|
|
exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT;
|
|
|
|
exception_ptr& operator=(nullptr_t) _NOEXCEPT;
|
|
|
|
~exception_ptr() _NOEXCEPT;
|
2021-06-16 00:57:54 +08:00
|
|
|
explicit operator bool() const _NOEXCEPT;
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
_LIBCPP_FUNC_VIS
|
|
|
|
bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT;
|
|
|
|
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
|
|
|
|
{return !(__x == __y);}
|
|
|
|
|
|
|
|
_LIBCPP_FUNC_VIS void swap(exception_ptr&, exception_ptr&) _NOEXCEPT;
|
|
|
|
|
|
|
|
_LIBCPP_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except, const void* __ptr);
|
|
|
|
_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT;
|
|
|
|
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr p);
|
|
|
|
|
|
|
|
// This is a built-in template function which automagically extracts the required
|
|
|
|
// information.
|
|
|
|
template <class _E> void *__GetExceptionInfo(_E);
|
|
|
|
|
|
|
|
template<class _Ep>
|
2018-11-22 01:00:52 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr
|
[libc++] Implement exception_ptr on Windows
Summary:
This patch implements exception_ptr on Windows using the `__ExceptionPtrFoo` functions provided by MSVC.
The `__ExceptionPtrFoo` functions are defined inside the C++ standard library, `msvcprt`, which is unfortunate because it requires libc++ to link to the MSVC STL. However this doesn't seem to cause any immediate problems. However to be safe I kept all usages within the libc++ dylib so that user programs wouldn't have to link to MSVCPRT as well.
Note there are still 2 outstanding exception_ptr/nested_exception test failures.
* `current_exception.pass.cpp` needs to be rewritten for the Windows exception_ptr semantics which copy the exception every time.
* `rethrow_if_nested.pass.cpp` need investigation. It hits a stack overflow, likely from recursion.
This patch also gets most of the `<future>` tests passing as well.
Reviewers: mclow.lists, compnerd, bcraig, rmaprath, majnemer, BillyONeal, STL_MSFT
Subscribers: mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D32927
llvm-svn: 302393
2017-05-08 09:17:50 +08:00
|
|
|
make_exception_ptr(_Ep __e) _NOEXCEPT
|
|
|
|
{
|
|
|
|
return __copy_exception_ptr(_VSTD::addressof(__e), __GetExceptionInfo(__e));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _LIBCPP_ABI_MICROSOFT
|
2010-05-28 01:06:52 +08:00
|
|
|
// nested_exception
|
|
|
|
|
|
|
|
class _LIBCPP_EXCEPTION_ABI nested_exception
|
|
|
|
{
|
|
|
|
exception_ptr __ptr_;
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
nested_exception() _NOEXCEPT;
|
|
|
|
// nested_exception(const nested_exception&) noexcept = default;
|
|
|
|
// nested_exception& operator=(const nested_exception&) noexcept = default;
|
|
|
|
virtual ~nested_exception() _NOEXCEPT;
|
2010-05-28 01:06:52 +08:00
|
|
|
|
|
|
|
// access functions
|
2012-07-26 10:04:22 +08:00
|
|
|
_LIBCPP_NORETURN void rethrow_nested() const;
|
2011-05-27 02:23:59 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;}
|
2010-05-28 01:06:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
struct __nested
|
|
|
|
: public _Tp,
|
|
|
|
public nested_exception
|
|
|
|
{
|
2010-09-22 05:28:23 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {}
|
2010-05-28 01:06:52 +08:00
|
|
|
};
|
|
|
|
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2017-04-13 22:41:45 +08:00
|
|
|
template <class _Tp, class _Up, bool>
|
|
|
|
struct __throw_with_nested;
|
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
struct __throw_with_nested<_Tp, _Up, true> {
|
2018-07-12 07:14:33 +08:00
|
|
|
_LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void
|
2017-04-13 22:41:45 +08:00
|
|
|
__do_throw(_Tp&& __t)
|
|
|
|
{
|
2021-06-05 10:47:47 +08:00
|
|
|
throw __nested<_Up>(static_cast<_Tp&&>(__t));
|
2017-04-13 22:41:45 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Up>
|
|
|
|
struct __throw_with_nested<_Tp, _Up, false> {
|
2018-07-12 07:14:33 +08:00
|
|
|
_LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void
|
2017-04-19 09:35:58 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2017-04-13 22:41:45 +08:00
|
|
|
__do_throw(_Tp&& __t)
|
2017-04-19 09:35:58 +08:00
|
|
|
#else
|
2017-04-13 22:41:45 +08:00
|
|
|
__do_throw (_Tp& __t)
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2017-04-13 22:41:45 +08:00
|
|
|
{
|
2021-06-05 10:47:47 +08:00
|
|
|
throw static_cast<_Tp&&>(__t);
|
2017-04-13 22:41:45 +08:00
|
|
|
}
|
|
|
|
};
|
2010-08-12 01:04:31 +08:00
|
|
|
#endif
|
2010-05-28 01:06:52 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2012-07-26 10:04:22 +08:00
|
|
|
_LIBCPP_NORETURN
|
2010-08-22 08:02:43 +08:00
|
|
|
void
|
2017-04-13 22:41:45 +08:00
|
|
|
throw_with_nested(_Tp&& __t)
|
2010-05-28 01:06:52 +08:00
|
|
|
{
|
2010-08-12 01:04:31 +08:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2017-04-14 00:57:42 +08:00
|
|
|
typedef typename decay<_Tp>::type _Up;
|
|
|
|
static_assert( is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible");
|
2017-04-13 22:41:45 +08:00
|
|
|
__throw_with_nested<_Tp, _Up,
|
|
|
|
is_class<_Up>::value &&
|
|
|
|
!is_base_of<nested_exception, _Up>::value &&
|
|
|
|
!__libcpp_is_final<_Up>::value>::
|
2021-06-05 10:47:47 +08:00
|
|
|
__do_throw(static_cast<_Tp&&>(__t));
|
2016-12-24 07:37:52 +08:00
|
|
|
#else
|
|
|
|
((void)__t);
|
|
|
|
// FIXME: Make this abort
|
2010-08-12 01:04:31 +08:00
|
|
|
#endif
|
2010-05-28 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
2017-03-15 01:08:47 +08:00
|
|
|
template <class _From, class _To>
|
2022-03-24 05:02:07 +08:00
|
|
|
struct __can_dynamic_cast : _BoolConstant<
|
2017-03-15 01:08:47 +08:00
|
|
|
is_polymorphic<_From>::value &&
|
|
|
|
(!is_base_of<_To, _From>::value ||
|
2022-03-24 05:02:07 +08:00
|
|
|
is_convertible<const _From*, const _To*>::value)> {};
|
2017-03-15 01:08:47 +08:00
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Ep>
|
2010-09-22 05:28:23 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-28 01:06:52 +08:00
|
|
|
void
|
2017-03-15 01:08:47 +08:00
|
|
|
rethrow_if_nested(const _Ep& __e,
|
|
|
|
typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)
|
2010-05-28 01:06:52 +08:00
|
|
|
{
|
2015-12-15 02:01:56 +08:00
|
|
|
const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e));
|
2010-05-28 21:35:41 +08:00
|
|
|
if (__nep)
|
|
|
|
__nep->rethrow_nested();
|
2010-05-28 01:06:52 +08:00
|
|
|
}
|
|
|
|
|
2011-11-30 02:15:50 +08:00
|
|
|
template <class _Ep>
|
2010-09-22 05:28:23 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-28 01:06:52 +08:00
|
|
|
void
|
2017-03-15 01:08:47 +08:00
|
|
|
rethrow_if_nested(const _Ep&,
|
|
|
|
typename enable_if<!__can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)
|
2010-05-28 01:06:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-12-02 21:12:51 +08:00
|
|
|
} // namespace std
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_EXCEPTION
|