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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// This test ensures that we can catch an Objective-C++ exception by type when
10// throwing an exception created via `std::make_exception_ptr`.
11// See http://llvm.org/PR135089.
12
13// UNSUPPORTED: no-exceptions
14// UNSUPPORTED: c++03
15
16// This test requires the Objective-C ARC, which is (only?) available on Darwin
17// out-of-the-box.
18// REQUIRES: has-fobjc-arc && darwin
19
20// ADDITIONAL_COMPILE_FLAGS: -fobjc-arc
21
22#include <cassert>
23#include <exception>
24
25#import <Foundation/Foundation.h>
26
27NSError* RecoverException(const std::exception_ptr& exc) {
28 try {
29 std::rethrow_exception(exc);
30 } catch (NSError* error) {
31 return error;
32 } catch (...) {
33 }
34 return nullptr;
35}
36
37int main(int, char**) {
38 NSError* error = [NSError errorWithDomain:NSPOSIXErrorDomain code:EPERM userInfo:nil];
39 std::exception_ptr exc = std::make_exception_ptr(error);
40 NSError* recov = RecoverException(exc);
41 assert(recov != nullptr);
42
43 return 0;
44}
45

source code of libcxx/test/std/language.support/support.exception/propagation/make_exception_ptr.objc.pass.mm