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