1 //===-------------------------- test_aux_runtime_op_array_new.cpp ---------===// 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: no-exceptions 10 11 // ___cxa_throw_bad_array_new_length is re-exported from libc++ only starting 12 // in macosx 10.15 13 // XFAIL: with_system_cxx_lib=macosx10.14 14 // XFAIL: with_system_cxx_lib=macosx10.13 15 // XFAIL: with_system_cxx_lib=macosx10.12 16 // XFAIL: with_system_cxx_lib=macosx10.11 17 // XFAIL: with_system_cxx_lib=macosx10.10 18 // XFAIL: with_system_cxx_lib=macosx10.9 19 20 #include <cxxabi.h> 21 #include <new> 22 23 // If the expression passed to operator new[] would result in an overflow, the 24 // allocation function is not called, and a std::bad_array_new_length exception 25 // is thrown instead (5.3.4p7). 26 bool bad_array_new_length_test() { 27 try { 28 // We test this directly because Clang does not currently codegen the 29 // correct call to __cxa_bad_array_new_length, so this test would result 30 // in passing -1 to ::operator new[], which would then throw a 31 // std::bad_alloc, causing the test to fail. 32 __cxxabiv1::__cxa_throw_bad_array_new_length(); 33 } catch ( const std::bad_array_new_length &banl ) { 34 return true; 35 } 36 return false; 37 } 38 39 int main(int, char**) { 40 int ret_val = 0; 41 42 if ( !bad_array_new_length_test ()) { 43 ret_val = 1; 44 } 45 46 return ret_val; 47 } 48