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