1 //===-------------------------- test_aux_runtime_op_array_new.cpp ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include <iostream>
11 #include <cxxabi.h>
12 
13 //  If the expression passed to operator new[] would result in an overflow, the
14 //  allocation function is not called, and a std::bad_array_new_length exception
15 //  is thrown instead (5.3.4p7).
bad_array_new_length_test()16 bool bad_array_new_length_test() {
17     try {
18       // We test this directly because Clang does not currently codegen the
19       // correct call to __cxa_bad_array_new_length, so this test would result
20       // in passing -1 to ::operator new[], which would then throw a
21       // std::bad_alloc, causing the test to fail.
22       __cxxabiv1::__cxa_throw_bad_array_new_length();
23     } catch ( const std::bad_array_new_length &banl ) {
24       return true;
25     }
26     return false;
27 }
28 
main(int argc,char * argv[])29 int main(int argc, char *argv []) {
30     int ret_val = 0;
31 
32     if ( !bad_array_new_length_test ()) {
33         std::cerr << "Bad array new length test failed!" << std::endl;
34         ret_val = 1;
35     }
36 
37     return ret_val;
38 }
39