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 // asan and msan will not call the new handler.
13 // UNSUPPORTED: sanitizer-new-delete
15 // FIXME change this to XFAIL.
16 // UNSUPPORTED: no-aligned-allocation
18 // XFAIL: with_system_cxx_lib=macosx10.12
19 // XFAIL: with_system_cxx_lib=macosx10.11
20 // XFAIL: with_system_cxx_lib=macosx10.10
21 // XFAIL: with_system_cxx_lib=macosx10.9
22 // XFAIL: with_system_cxx_lib=macosx10.7
23 // XFAIL: with_system_cxx_lib=macosx10.8
26 // On Windows libc++ doesn't provide its own definitions for new/delete
27 // but instead depends on the ones in VCRuntime. However VCRuntime does not
28 // yet provide aligned new/delete definitions so this test fails to link.
29 // XFAIL: LIBCXX-WINDOWS-FIXME
39 #include "test_macros.h"
41 constexpr auto OverAligned = alignof(std::max_align_t) * 2;
43 int new_handler_called = 0;
48 std::set_new_handler(0);
51 int A_constructed = 0;
53 struct alignas(OverAligned) A
55 A() { ++A_constructed;}
56 ~A() { --A_constructed;}
59 void test_throw_max_size() {
60 #ifndef TEST_HAS_NO_EXCEPTIONS
61 std::set_new_handler(my_new_handler);
64 void* vp = operator new[] (std::numeric_limits<std::size_t>::max(),
65 static_cast<std::align_val_t>(32));
69 catch (std::bad_alloc&)
71 assert(new_handler_called == 1);
85 assert(reinterpret_cast<std::uintptr_t>(ap) % OverAligned == 0);
86 assert(A_constructed == 2);
88 assert(A_constructed == 0);
91 test_throw_max_size();