146035553Spatrick// -*- C++ -*- 246035553Spatrick//===----------------------------------------------------------------------===// 346035553Spatrick// 446035553Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 546035553Spatrick// See https://llvm.org/LICENSE.txt for license information. 646035553Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 746035553Spatrick// 846035553Spatrick//===----------------------------------------------------------------------===// 946035553Spatrick 1046035553Spatrick#ifndef HAVE_DEPENDENT_EH_ABI 1146035553Spatrick#error this header may only be used with libc++abi or libcxxrt 1246035553Spatrick#endif 1346035553Spatrick 1446035553Spatricknamespace std { 1546035553Spatrick 16*76d0caaeSpatrickexception_ptr::~exception_ptr() noexcept { 1746035553Spatrick __cxa_decrement_exception_refcount(__ptr_); 1846035553Spatrick} 1946035553Spatrick 20*76d0caaeSpatrickexception_ptr::exception_ptr(const exception_ptr& other) noexcept 2146035553Spatrick : __ptr_(other.__ptr_) 2246035553Spatrick{ 2346035553Spatrick __cxa_increment_exception_refcount(__ptr_); 2446035553Spatrick} 2546035553Spatrick 26*76d0caaeSpatrickexception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept 2746035553Spatrick{ 2846035553Spatrick if (__ptr_ != other.__ptr_) 2946035553Spatrick { 3046035553Spatrick __cxa_increment_exception_refcount(other.__ptr_); 3146035553Spatrick __cxa_decrement_exception_refcount(__ptr_); 3246035553Spatrick __ptr_ = other.__ptr_; 3346035553Spatrick } 3446035553Spatrick return *this; 3546035553Spatrick} 3646035553Spatrick 37*76d0caaeSpatricknested_exception::nested_exception() noexcept 3846035553Spatrick : __ptr_(current_exception()) 3946035553Spatrick{ 4046035553Spatrick} 4146035553Spatrick 42*76d0caaeSpatricknested_exception::~nested_exception() noexcept 4346035553Spatrick{ 4446035553Spatrick} 4546035553Spatrick 4646035553Spatrick_LIBCPP_NORETURN 4746035553Spatrickvoid 4846035553Spatricknested_exception::rethrow_nested() const 4946035553Spatrick{ 5046035553Spatrick if (__ptr_ == nullptr) 5146035553Spatrick terminate(); 5246035553Spatrick rethrow_exception(__ptr_); 5346035553Spatrick} 5446035553Spatrick 55*76d0caaeSpatrickexception_ptr current_exception() noexcept 5646035553Spatrick{ 5746035553Spatrick // be nicer if there was a constructor that took a ptr, then 5846035553Spatrick // this whole function would be just: 5946035553Spatrick // return exception_ptr(__cxa_current_primary_exception()); 6046035553Spatrick exception_ptr ptr; 6146035553Spatrick ptr.__ptr_ = __cxa_current_primary_exception(); 6246035553Spatrick return ptr; 6346035553Spatrick} 6446035553Spatrick 6546035553Spatrick_LIBCPP_NORETURN 6646035553Spatrickvoid rethrow_exception(exception_ptr p) 6746035553Spatrick{ 6846035553Spatrick __cxa_rethrow_primary_exception(p.__ptr_); 6946035553Spatrick // if p.__ptr_ is NULL, above returns so we terminate 7046035553Spatrick terminate(); 7146035553Spatrick} 7246035553Spatrick 7346035553Spatrick} // namespace std 74