brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 4b08db6 Raw
71 lines · plain
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10// libsupc++ does not implement the dependent EH ABI and the functionality11// it uses to implement std::exception_ptr (which it declares as an alias of12// std::__exception_ptr::exception_ptr) is not directly exported to clients. So13// we have little choice but to hijack std::__exception_ptr::exception_ptr's14// (which fortunately has the same layout as our std::exception_ptr) copy15// constructor, assignment operator and destructor (which are part of its16// stable ABI), and its rethrow_exception(std::__exception_ptr::exception_ptr)17// function.18 19#include <exception>20 21namespace std {22 23namespace __exception_ptr {24 25struct exception_ptr {26  void* __ptr_;27 28  explicit exception_ptr(void*) noexcept;29  exception_ptr(const exception_ptr&) noexcept;30  exception_ptr& operator=(const exception_ptr&) noexcept;31  ~exception_ptr() noexcept;32};33 34} // namespace __exception_ptr35 36[[noreturn]] void rethrow_exception(__exception_ptr::exception_ptr);37 38exception_ptr::~exception_ptr() noexcept { reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); }39 40exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {41  new (reinterpret_cast<void*>(this))42      __exception_ptr::exception_ptr(reinterpret_cast<const __exception_ptr::exception_ptr&>(other));43}44 45exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {46  *reinterpret_cast<__exception_ptr::exception_ptr*>(this) =47      reinterpret_cast<const __exception_ptr::exception_ptr&>(other);48  return *this;49}50 51exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {52  exception_ptr ptr{};53  new (reinterpret_cast<void*>(&ptr)) __exception_ptr::exception_ptr(__e);54 55  return ptr;56}57 58nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}59 60[[noreturn]] void nested_exception::rethrow_nested() const {61  if (__ptr_ == nullptr)62    terminate();63  rethrow_exception(__ptr_);64}65 66[[noreturn]] void rethrow_exception(exception_ptr p) {67  rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p));68}69 70} // namespace std71