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 // test operator new (nothrow)
26 #include "test_macros.h"
28 constexpr auto OverAligned = alignof(std::max_align_t) * 2;
30 int new_handler_called = 0;
35 std::set_new_handler(0);
38 bool A_constructed = false;
40 struct alignas(OverAligned) A
42 A() {A_constructed = true;}
43 ~A() {A_constructed = false;}
46 void test_max_alloc() {
47 std::set_new_handler(new_handler);
49 void* vp = operator new (std::numeric_limits<std::size_t>::max(),
50 std::align_val_t(OverAligned),
52 assert(new_handler_called == 1);
55 #ifndef TEST_HAS_NO_EXCEPTIONS
72 A* ap = new(std::nothrow) A;
74 assert(reinterpret_cast<std::uintptr_t>(ap) % OverAligned == 0);
75 assert(A_constructed);
77 assert(!A_constructed);