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 // UNSUPPORTED: libcpp-no-exceptions 10 // XFAIL: libcpp-no-exceptions 11 12 // std::uncaught_exceptions() was introduced in the dylib on Mac OS 10.12 13 // XFAIL: with_system_cxx_lib=macosx10.11 14 // XFAIL: with_system_cxx_lib=macosx10.10 15 // XFAIL: with_system_cxx_lib=macosx10.9 16 17 // However, std::uncaught_exceptions() gives the wrong answer in Mac OS 10.12 18 // and 10.13, where it only gives 0 or 1. This was fixed later. 19 // XFAIL: with_system_cxx_lib=macosx10.13 20 // XFAIL: with_system_cxx_lib=macosx10.12 21 22 // test uncaught_exceptions 23 24 #include <exception> 25 #include <cassert> 26 27 #include "test_macros.h" 28 29 struct Uncaught { 30 Uncaught(int depth) : d_(depth) {} 31 ~Uncaught() { assert(std::uncaught_exceptions() == d_); } 32 int d_; 33 }; 34 35 struct Outer { 36 Outer(int depth) : d_(depth) {} 37 ~Outer() { 38 try { 39 assert(std::uncaught_exceptions() == d_); 40 Uncaught u(d_+1); 41 throw 2; 42 } 43 catch (int) {} 44 } 45 int d_; 46 }; 47 48 int main(int, char**) { 49 assert(std::uncaught_exceptions() == 0); 50 { 51 Outer o(0); 52 } 53 54 assert(std::uncaught_exceptions() == 0); 55 { 56 try { 57 Outer o(1); 58 throw 1; 59 } 60 catch (int) { 61 assert(std::uncaught_exceptions() == 0); 62 } 63 } 64 assert(std::uncaught_exceptions() == 0); 65 66 return 0; 67 } 68