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