llvm-capstone/libcxxabi/test/test_aux_runtime_op_array_new.pass.cpp
Chandler Carruth 57b08b0944 Update more file headers across all of the LLVM projects in the monorepo
to reflect the new license. These used slightly different spellings that
defeated my regular expressions.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351648
2019-01-19 10:56:40 +00:00

40 lines
1.3 KiB
C++

//===-------------------------- test_aux_runtime_op_array_new.cpp ---------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: libcxxabi-no-exceptions
#include <iostream>
#include <cxxabi.h>
// If the expression passed to operator new[] would result in an overflow, the
// allocation function is not called, and a std::bad_array_new_length exception
// is thrown instead (5.3.4p7).
bool bad_array_new_length_test() {
try {
// We test this directly because Clang does not currently codegen the
// correct call to __cxa_bad_array_new_length, so this test would result
// in passing -1 to ::operator new[], which would then throw a
// std::bad_alloc, causing the test to fail.
__cxxabiv1::__cxa_throw_bad_array_new_length();
} catch ( const std::bad_array_new_length &banl ) {
return true;
}
return false;
}
int main() {
int ret_val = 0;
if ( !bad_array_new_length_test ()) {
std::cerr << "Bad array new length test failed!" << std::endl;
ret_val = 1;
}
return ret_val;
}