68 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-exceptions10// <exception>11 12// void rethrow_exception [[noreturn]] (exception_ptr p);13 14#include <exception>15#include <cassert>16 17#include "test_macros.h"18 19struct A20{21 static int constructed;22 int data_;23 24 A(int data = 0) : data_(data) {++constructed;}25 ~A() {--constructed;}26 A(const A& a) : data_(a.data_) {++constructed;}27};28 29int A::constructed = 0;30 31int main(int, char**)32{33 {34 std::exception_ptr p;35 try36 {37 throw A(3);38 }39 catch (...)40 {41 p = std::current_exception();42 }43 try44 {45 std::rethrow_exception(p);46 assert(false);47 }48 catch (const A& a)49 {50#ifndef TEST_ABI_MICROSOFT51 assert(A::constructed == 1);52#else53 // On Windows the exception_ptr copies the exception54 assert(A::constructed == 2);55#endif56 assert(p != nullptr);57 p = nullptr;58 assert(p == nullptr);59 assert(a.data_ == 3);60 assert(A::constructed == 1);61 }62 assert(A::constructed == 0);63 }64 assert(A::constructed == 0);65 66 return 0;67}68