1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
12 // XFAIL: with_system_cxx_lib=macosx10.12
13 // XFAIL: with_system_cxx_lib=macosx10.11
14 // XFAIL: with_system_cxx_lib=macosx10.10
15 // XFAIL: with_system_cxx_lib=macosx10.9
16 // XFAIL: with_system_cxx_lib=macosx10.7
17 // XFAIL: with_system_cxx_lib=macosx10.8
19 // asan and msan will not call the new handler.
20 // UNSUPPORTED: sanitizer-new-delete
22 // FIXME turn this into an XFAIL
23 // UNSUPPORTED: no-aligned-allocation
25 // On Windows libc++ doesn't provide its own definitions for new/delete
26 // but instead depends on the ones in VCRuntime. However VCRuntime does not
27 // yet provide aligned new/delete definitions so this test fails to compile/link.
28 // XFAIL: LIBCXX-WINDOWS-FIXME
38 #include "test_macros.h"
40 constexpr auto OverAligned = alignof(std::max_align_t) * 2;
42 int new_handler_called = 0;
47 std::set_new_handler(0);
50 bool A_constructed = false;
52 struct alignas(OverAligned) A
54 A() {A_constructed = true;}
55 ~A() {A_constructed = false;}
58 void test_throw_max_size() {
59 #ifndef TEST_HAS_NO_EXCEPTIONS
60 std::set_new_handler(my_new_handler);
63 void* vp = operator new (std::numeric_limits<std::size_t>::max(),
64 static_cast<std::align_val_t>(32));
68 catch (std::bad_alloc&)
70 assert(new_handler_called == 1);
84 assert(reinterpret_cast<std::uintptr_t>(ap) % OverAligned == 0);
85 assert(A_constructed);
87 assert(!A_constructed);
90 test_throw_max_size();