1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*- 2*58b9f456SAndroid Build Coastguard Worker//===-------------------------- exception ---------------------------------===// 3*58b9f456SAndroid Build Coastguard Worker// 4*58b9f456SAndroid Build Coastguard Worker// The LLVM Compiler Infrastructure 5*58b9f456SAndroid Build Coastguard Worker// 6*58b9f456SAndroid Build Coastguard Worker// This file is dual licensed under the MIT and the University of Illinois Open 7*58b9f456SAndroid Build Coastguard Worker// Source Licenses. See LICENSE.TXT for details. 8*58b9f456SAndroid Build Coastguard Worker// 9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===// 10*58b9f456SAndroid Build Coastguard Worker 11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_EXCEPTION 12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_EXCEPTION 13*58b9f456SAndroid Build Coastguard Worker 14*58b9f456SAndroid Build Coastguard Worker/* 15*58b9f456SAndroid Build Coastguard Worker exception synopsis 16*58b9f456SAndroid Build Coastguard Worker 17*58b9f456SAndroid Build Coastguard Workernamespace std 18*58b9f456SAndroid Build Coastguard Worker{ 19*58b9f456SAndroid Build Coastguard Worker 20*58b9f456SAndroid Build Coastguard Workerclass exception 21*58b9f456SAndroid Build Coastguard Worker{ 22*58b9f456SAndroid Build Coastguard Workerpublic: 23*58b9f456SAndroid Build Coastguard Worker exception() noexcept; 24*58b9f456SAndroid Build Coastguard Worker exception(const exception&) noexcept; 25*58b9f456SAndroid Build Coastguard Worker exception& operator=(const exception&) noexcept; 26*58b9f456SAndroid Build Coastguard Worker virtual ~exception() noexcept; 27*58b9f456SAndroid Build Coastguard Worker virtual const char* what() const noexcept; 28*58b9f456SAndroid Build Coastguard Worker}; 29*58b9f456SAndroid Build Coastguard Worker 30*58b9f456SAndroid Build Coastguard Workerclass bad_exception 31*58b9f456SAndroid Build Coastguard Worker : public exception 32*58b9f456SAndroid Build Coastguard Worker{ 33*58b9f456SAndroid Build Coastguard Workerpublic: 34*58b9f456SAndroid Build Coastguard Worker bad_exception() noexcept; 35*58b9f456SAndroid Build Coastguard Worker bad_exception(const bad_exception&) noexcept; 36*58b9f456SAndroid Build Coastguard Worker bad_exception& operator=(const bad_exception&) noexcept; 37*58b9f456SAndroid Build Coastguard Worker virtual ~bad_exception() noexcept; 38*58b9f456SAndroid Build Coastguard Worker virtual const char* what() const noexcept; 39*58b9f456SAndroid Build Coastguard Worker}; 40*58b9f456SAndroid Build Coastguard Worker 41*58b9f456SAndroid Build Coastguard Workertypedef void (*unexpected_handler)(); 42*58b9f456SAndroid Build Coastguard Workerunexpected_handler set_unexpected(unexpected_handler f ) noexcept; 43*58b9f456SAndroid Build Coastguard Workerunexpected_handler get_unexpected() noexcept; 44*58b9f456SAndroid Build Coastguard Worker[[noreturn]] void unexpected(); 45*58b9f456SAndroid Build Coastguard Worker 46*58b9f456SAndroid Build Coastguard Workertypedef void (*terminate_handler)(); 47*58b9f456SAndroid Build Coastguard Workerterminate_handler set_terminate(terminate_handler f ) noexcept; 48*58b9f456SAndroid Build Coastguard Workerterminate_handler get_terminate() noexcept; 49*58b9f456SAndroid Build Coastguard Worker[[noreturn]] void terminate() noexcept; 50*58b9f456SAndroid Build Coastguard Worker 51*58b9f456SAndroid Build Coastguard Workerbool uncaught_exception() noexcept; 52*58b9f456SAndroid Build Coastguard Workerint uncaught_exceptions() noexcept; // C++17 53*58b9f456SAndroid Build Coastguard Worker 54*58b9f456SAndroid Build Coastguard Workertypedef unspecified exception_ptr; 55*58b9f456SAndroid Build Coastguard Worker 56*58b9f456SAndroid Build Coastguard Workerexception_ptr current_exception() noexcept; 57*58b9f456SAndroid Build Coastguard Workervoid rethrow_exception [[noreturn]] (exception_ptr p); 58*58b9f456SAndroid Build Coastguard Workertemplate<class E> exception_ptr make_exception_ptr(E e) noexcept; 59*58b9f456SAndroid Build Coastguard Worker 60*58b9f456SAndroid Build Coastguard Workerclass nested_exception 61*58b9f456SAndroid Build Coastguard Worker{ 62*58b9f456SAndroid Build Coastguard Workerpublic: 63*58b9f456SAndroid Build Coastguard Worker nested_exception() noexcept; 64*58b9f456SAndroid Build Coastguard Worker nested_exception(const nested_exception&) noexcept = default; 65*58b9f456SAndroid Build Coastguard Worker nested_exception& operator=(const nested_exception&) noexcept = default; 66*58b9f456SAndroid Build Coastguard Worker virtual ~nested_exception() = default; 67*58b9f456SAndroid Build Coastguard Worker 68*58b9f456SAndroid Build Coastguard Worker // access functions 69*58b9f456SAndroid Build Coastguard Worker [[noreturn]] void rethrow_nested() const; 70*58b9f456SAndroid Build Coastguard Worker exception_ptr nested_ptr() const noexcept; 71*58b9f456SAndroid Build Coastguard Worker}; 72*58b9f456SAndroid Build Coastguard Worker 73*58b9f456SAndroid Build Coastguard Workertemplate <class T> [[noreturn]] void throw_with_nested(T&& t); 74*58b9f456SAndroid Build Coastguard Workertemplate <class E> void rethrow_if_nested(const E& e); 75*58b9f456SAndroid Build Coastguard Worker 76*58b9f456SAndroid Build Coastguard Worker} // std 77*58b9f456SAndroid Build Coastguard Worker 78*58b9f456SAndroid Build Coastguard Worker*/ 79*58b9f456SAndroid Build Coastguard Worker 80*58b9f456SAndroid Build Coastguard Worker#include <__config> 81*58b9f456SAndroid Build Coastguard Worker#include <cstddef> 82*58b9f456SAndroid Build Coastguard Worker#include <cstdlib> 83*58b9f456SAndroid Build Coastguard Worker#include <type_traits> 84*58b9f456SAndroid Build Coastguard Worker#include <version> 85*58b9f456SAndroid Build Coastguard Worker 86*58b9f456SAndroid Build Coastguard Worker#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 87*58b9f456SAndroid Build Coastguard Worker#include <vcruntime_exception.h> 88*58b9f456SAndroid Build Coastguard Worker#endif 89*58b9f456SAndroid Build Coastguard Worker 90*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 91*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header 92*58b9f456SAndroid Build Coastguard Worker#endif 93*58b9f456SAndroid Build Coastguard Worker 94*58b9f456SAndroid Build Coastguard Workernamespace std // purposefully not using versioning namespace 95*58b9f456SAndroid Build Coastguard Worker{ 96*58b9f456SAndroid Build Coastguard Worker 97*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) 98*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI exception 99*58b9f456SAndroid Build Coastguard Worker{ 100*58b9f456SAndroid Build Coastguard Workerpublic: 101*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {} 102*58b9f456SAndroid Build Coastguard Worker virtual ~exception() _NOEXCEPT; 103*58b9f456SAndroid Build Coastguard Worker virtual const char* what() const _NOEXCEPT; 104*58b9f456SAndroid Build Coastguard Worker}; 105*58b9f456SAndroid Build Coastguard Worker 106*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI bad_exception 107*58b9f456SAndroid Build Coastguard Worker : public exception 108*58b9f456SAndroid Build Coastguard Worker{ 109*58b9f456SAndroid Build Coastguard Workerpublic: 110*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY bad_exception() _NOEXCEPT {} 111*58b9f456SAndroid Build Coastguard Worker virtual ~bad_exception() _NOEXCEPT; 112*58b9f456SAndroid Build Coastguard Worker virtual const char* what() const _NOEXCEPT; 113*58b9f456SAndroid Build Coastguard Worker}; 114*58b9f456SAndroid Build Coastguard Worker#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME 115*58b9f456SAndroid Build Coastguard Worker 116*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 \ 117*58b9f456SAndroid Build Coastguard Worker || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \ 118*58b9f456SAndroid Build Coastguard Worker || defined(_LIBCPP_BUILDING_LIBRARY) 119*58b9f456SAndroid Build Coastguard Workertypedef void (*unexpected_handler)(); 120*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT; 121*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT; 122*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected(); 123*58b9f456SAndroid Build Coastguard Worker#endif 124*58b9f456SAndroid Build Coastguard Worker 125*58b9f456SAndroid Build Coastguard Workertypedef void (*terminate_handler)(); 126*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT; 127*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS terminate_handler get_terminate() _NOEXCEPT; 128*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT; 129*58b9f456SAndroid Build Coastguard Worker 130*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT; 131*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS int uncaught_exceptions() _NOEXCEPT; 132*58b9f456SAndroid Build Coastguard Worker 133*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS exception_ptr; 134*58b9f456SAndroid Build Coastguard Worker 135*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; 136*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr); 137*58b9f456SAndroid Build Coastguard Worker 138*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_ABI_MICROSOFT 139*58b9f456SAndroid Build Coastguard Worker 140*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS exception_ptr 141*58b9f456SAndroid Build Coastguard Worker{ 142*58b9f456SAndroid Build Coastguard Worker void* __ptr_; 143*58b9f456SAndroid Build Coastguard Workerpublic: 144*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {} 145*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {} 146*58b9f456SAndroid Build Coastguard Worker 147*58b9f456SAndroid Build Coastguard Worker exception_ptr(const exception_ptr&) _NOEXCEPT; 148*58b9f456SAndroid Build Coastguard Worker exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; 149*58b9f456SAndroid Build Coastguard Worker ~exception_ptr() _NOEXCEPT; 150*58b9f456SAndroid Build Coastguard Worker 151*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT 152*58b9f456SAndroid Build Coastguard Worker {return __ptr_ != nullptr;} 153*58b9f456SAndroid Build Coastguard Worker 154*58b9f456SAndroid Build Coastguard Worker friend _LIBCPP_INLINE_VISIBILITY 155*58b9f456SAndroid Build Coastguard Worker bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT 156*58b9f456SAndroid Build Coastguard Worker {return __x.__ptr_ == __y.__ptr_;} 157*58b9f456SAndroid Build Coastguard Worker 158*58b9f456SAndroid Build Coastguard Worker friend _LIBCPP_INLINE_VISIBILITY 159*58b9f456SAndroid Build Coastguard Worker bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT 160*58b9f456SAndroid Build Coastguard Worker {return !(__x == __y);} 161*58b9f456SAndroid Build Coastguard Worker 162*58b9f456SAndroid Build Coastguard Worker friend _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; 163*58b9f456SAndroid Build Coastguard Worker friend _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr); 164*58b9f456SAndroid Build Coastguard Worker}; 165*58b9f456SAndroid Build Coastguard Worker 166*58b9f456SAndroid Build Coastguard Workertemplate<class _Ep> 167*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VISIBILITY exception_ptr 168*58b9f456SAndroid Build Coastguard Workermake_exception_ptr(_Ep __e) _NOEXCEPT 169*58b9f456SAndroid Build Coastguard Worker{ 170*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS 171*58b9f456SAndroid Build Coastguard Worker try 172*58b9f456SAndroid Build Coastguard Worker { 173*58b9f456SAndroid Build Coastguard Worker throw __e; 174*58b9f456SAndroid Build Coastguard Worker } 175*58b9f456SAndroid Build Coastguard Worker catch (...) 176*58b9f456SAndroid Build Coastguard Worker { 177*58b9f456SAndroid Build Coastguard Worker return current_exception(); 178*58b9f456SAndroid Build Coastguard Worker } 179*58b9f456SAndroid Build Coastguard Worker#else 180*58b9f456SAndroid Build Coastguard Worker ((void)__e); 181*58b9f456SAndroid Build Coastguard Worker _VSTD::abort(); 182*58b9f456SAndroid Build Coastguard Worker#endif 183*58b9f456SAndroid Build Coastguard Worker} 184*58b9f456SAndroid Build Coastguard Worker 185*58b9f456SAndroid Build Coastguard Worker#else // _LIBCPP_ABI_MICROSOFT 186*58b9f456SAndroid Build Coastguard Worker 187*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS exception_ptr 188*58b9f456SAndroid Build Coastguard Worker{ 189*58b9f456SAndroid Build Coastguard Worker#if defined(__clang__) 190*58b9f456SAndroid Build Coastguard Worker#pragma clang diagnostic push 191*58b9f456SAndroid Build Coastguard Worker#pragma clang diagnostic ignored "-Wunused-private-field" 192*58b9f456SAndroid Build Coastguard Worker#endif 193*58b9f456SAndroid Build Coastguard Worker void* __ptr1_; 194*58b9f456SAndroid Build Coastguard Worker void* __ptr2_; 195*58b9f456SAndroid Build Coastguard Worker#if defined(__clang__) 196*58b9f456SAndroid Build Coastguard Worker#pragma clang diagnostic pop 197*58b9f456SAndroid Build Coastguard Worker#endif 198*58b9f456SAndroid Build Coastguard Workerpublic: 199*58b9f456SAndroid Build Coastguard Worker exception_ptr() _NOEXCEPT; 200*58b9f456SAndroid Build Coastguard Worker exception_ptr(nullptr_t) _NOEXCEPT; 201*58b9f456SAndroid Build Coastguard Worker exception_ptr(const exception_ptr& __other) _NOEXCEPT; 202*58b9f456SAndroid Build Coastguard Worker exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT; 203*58b9f456SAndroid Build Coastguard Worker exception_ptr& operator=(nullptr_t) _NOEXCEPT; 204*58b9f456SAndroid Build Coastguard Worker ~exception_ptr() _NOEXCEPT; 205*58b9f456SAndroid Build Coastguard Worker _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT; 206*58b9f456SAndroid Build Coastguard Worker}; 207*58b9f456SAndroid Build Coastguard Worker 208*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS 209*58b9f456SAndroid Build Coastguard Workerbool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT; 210*58b9f456SAndroid Build Coastguard Worker 211*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY 212*58b9f456SAndroid Build Coastguard Workerbool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT 213*58b9f456SAndroid Build Coastguard Worker {return !(__x == __y);} 214*58b9f456SAndroid Build Coastguard Worker 215*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS void swap(exception_ptr&, exception_ptr&) _NOEXCEPT; 216*58b9f456SAndroid Build Coastguard Worker 217*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except, const void* __ptr); 218*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT; 219*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr p); 220*58b9f456SAndroid Build Coastguard Worker 221*58b9f456SAndroid Build Coastguard Worker// This is a built-in template function which automagically extracts the required 222*58b9f456SAndroid Build Coastguard Worker// information. 223*58b9f456SAndroid Build Coastguard Workertemplate <class _E> void *__GetExceptionInfo(_E); 224*58b9f456SAndroid Build Coastguard Worker 225*58b9f456SAndroid Build Coastguard Workertemplate<class _Ep> 226*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VISIBILITY exception_ptr 227*58b9f456SAndroid Build Coastguard Workermake_exception_ptr(_Ep __e) _NOEXCEPT 228*58b9f456SAndroid Build Coastguard Worker{ 229*58b9f456SAndroid Build Coastguard Worker return __copy_exception_ptr(_VSTD::addressof(__e), __GetExceptionInfo(__e)); 230*58b9f456SAndroid Build Coastguard Worker} 231*58b9f456SAndroid Build Coastguard Worker 232*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_ABI_MICROSOFT 233*58b9f456SAndroid Build Coastguard Worker// nested_exception 234*58b9f456SAndroid Build Coastguard Worker 235*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI nested_exception 236*58b9f456SAndroid Build Coastguard Worker{ 237*58b9f456SAndroid Build Coastguard Worker exception_ptr __ptr_; 238*58b9f456SAndroid Build Coastguard Workerpublic: 239*58b9f456SAndroid Build Coastguard Worker nested_exception() _NOEXCEPT; 240*58b9f456SAndroid Build Coastguard Worker// nested_exception(const nested_exception&) noexcept = default; 241*58b9f456SAndroid Build Coastguard Worker// nested_exception& operator=(const nested_exception&) noexcept = default; 242*58b9f456SAndroid Build Coastguard Worker virtual ~nested_exception() _NOEXCEPT; 243*58b9f456SAndroid Build Coastguard Worker 244*58b9f456SAndroid Build Coastguard Worker // access functions 245*58b9f456SAndroid Build Coastguard Worker _LIBCPP_NORETURN void rethrow_nested() const; 246*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;} 247*58b9f456SAndroid Build Coastguard Worker}; 248*58b9f456SAndroid Build Coastguard Worker 249*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp> 250*58b9f456SAndroid Build Coastguard Workerstruct __nested 251*58b9f456SAndroid Build Coastguard Worker : public _Tp, 252*58b9f456SAndroid Build Coastguard Worker public nested_exception 253*58b9f456SAndroid Build Coastguard Worker{ 254*58b9f456SAndroid Build Coastguard Worker _LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {} 255*58b9f456SAndroid Build Coastguard Worker}; 256*58b9f456SAndroid Build Coastguard Worker 257*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS 258*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up, bool> 259*58b9f456SAndroid Build Coastguard Workerstruct __throw_with_nested; 260*58b9f456SAndroid Build Coastguard Worker 261*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up> 262*58b9f456SAndroid Build Coastguard Workerstruct __throw_with_nested<_Tp, _Up, true> { 263*58b9f456SAndroid Build Coastguard Worker _LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void 264*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 265*58b9f456SAndroid Build Coastguard Worker __do_throw(_Tp&& __t) 266*58b9f456SAndroid Build Coastguard Worker#else 267*58b9f456SAndroid Build Coastguard Worker __do_throw (_Tp& __t) 268*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG 269*58b9f456SAndroid Build Coastguard Worker { 270*58b9f456SAndroid Build Coastguard Worker throw __nested<_Up>(_VSTD::forward<_Tp>(__t)); 271*58b9f456SAndroid Build Coastguard Worker } 272*58b9f456SAndroid Build Coastguard Worker}; 273*58b9f456SAndroid Build Coastguard Worker 274*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up> 275*58b9f456SAndroid Build Coastguard Workerstruct __throw_with_nested<_Tp, _Up, false> { 276*58b9f456SAndroid Build Coastguard Worker _LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void 277*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 278*58b9f456SAndroid Build Coastguard Worker __do_throw(_Tp&& __t) 279*58b9f456SAndroid Build Coastguard Worker#else 280*58b9f456SAndroid Build Coastguard Worker __do_throw (_Tp& __t) 281*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG 282*58b9f456SAndroid Build Coastguard Worker { 283*58b9f456SAndroid Build Coastguard Worker throw _VSTD::forward<_Tp>(__t); 284*58b9f456SAndroid Build Coastguard Worker } 285*58b9f456SAndroid Build Coastguard Worker}; 286*58b9f456SAndroid Build Coastguard Worker#endif 287*58b9f456SAndroid Build Coastguard Worker 288*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp> 289*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN 290*58b9f456SAndroid Build Coastguard Workervoid 291*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG 292*58b9f456SAndroid Build Coastguard Workerthrow_with_nested(_Tp&& __t) 293*58b9f456SAndroid Build Coastguard Worker#else 294*58b9f456SAndroid Build Coastguard Workerthrow_with_nested (_Tp& __t) 295*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG 296*58b9f456SAndroid Build Coastguard Worker{ 297*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS 298*58b9f456SAndroid Build Coastguard Worker typedef typename decay<_Tp>::type _Up; 299*58b9f456SAndroid Build Coastguard Worker static_assert( is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible"); 300*58b9f456SAndroid Build Coastguard Worker __throw_with_nested<_Tp, _Up, 301*58b9f456SAndroid Build Coastguard Worker is_class<_Up>::value && 302*58b9f456SAndroid Build Coastguard Worker !is_base_of<nested_exception, _Up>::value && 303*58b9f456SAndroid Build Coastguard Worker !__libcpp_is_final<_Up>::value>:: 304*58b9f456SAndroid Build Coastguard Worker __do_throw(_VSTD::forward<_Tp>(__t)); 305*58b9f456SAndroid Build Coastguard Worker#else 306*58b9f456SAndroid Build Coastguard Worker ((void)__t); 307*58b9f456SAndroid Build Coastguard Worker // FIXME: Make this abort 308*58b9f456SAndroid Build Coastguard Worker#endif 309*58b9f456SAndroid Build Coastguard Worker} 310*58b9f456SAndroid Build Coastguard Worker 311*58b9f456SAndroid Build Coastguard Workertemplate <class _From, class _To> 312*58b9f456SAndroid Build Coastguard Workerstruct __can_dynamic_cast : public _LIBCPP_BOOL_CONSTANT( 313*58b9f456SAndroid Build Coastguard Worker is_polymorphic<_From>::value && 314*58b9f456SAndroid Build Coastguard Worker (!is_base_of<_To, _From>::value || 315*58b9f456SAndroid Build Coastguard Worker is_convertible<const _From*, const _To*>::value)) {}; 316*58b9f456SAndroid Build Coastguard Worker 317*58b9f456SAndroid Build Coastguard Workertemplate <class _Ep> 318*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY 319*58b9f456SAndroid Build Coastguard Workervoid 320*58b9f456SAndroid Build Coastguard Workerrethrow_if_nested(const _Ep& __e, 321*58b9f456SAndroid Build Coastguard Worker typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0) 322*58b9f456SAndroid Build Coastguard Worker{ 323*58b9f456SAndroid Build Coastguard Worker const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e)); 324*58b9f456SAndroid Build Coastguard Worker if (__nep) 325*58b9f456SAndroid Build Coastguard Worker __nep->rethrow_nested(); 326*58b9f456SAndroid Build Coastguard Worker} 327*58b9f456SAndroid Build Coastguard Worker 328*58b9f456SAndroid Build Coastguard Workertemplate <class _Ep> 329*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY 330*58b9f456SAndroid Build Coastguard Workervoid 331*58b9f456SAndroid Build Coastguard Workerrethrow_if_nested(const _Ep&, 332*58b9f456SAndroid Build Coastguard Worker typename enable_if<!__can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0) 333*58b9f456SAndroid Build Coastguard Worker{ 334*58b9f456SAndroid Build Coastguard Worker} 335*58b9f456SAndroid Build Coastguard Worker 336*58b9f456SAndroid Build Coastguard Worker} // std 337*58b9f456SAndroid Build Coastguard Worker 338*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_EXCEPTION 339