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 turn this into an 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
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
30 // test operator new (nothrow)
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 int A_constructed = 0;
52 struct alignas(OverAligned) A
54 A() { ++A_constructed; }
55 ~A() { --A_constructed; }
58 void test_max_alloc() {
59 std::set_new_handler(my_new_handler);
61 void* vp = operator new [](std::numeric_limits<std::size_t>::max(),
62 std::align_val_t(OverAligned),
64 assert(new_handler_called == 1);
67 #ifndef TEST_HAS_NO_EXCEPTIONS
84 A* ap = new(std::nothrow) A[3];
86 assert(reinterpret_cast<std::uintptr_t>(ap) % OverAligned == 0);
87 assert(A_constructed == 3);
89 assert(!A_constructed);