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
11 // UNSUPPORTED: sanitizer-new-delete
13 // XFAIL: no-aligned-allocation
15 // test operator new replacement
24 #include "test_macros.h"
26 constexpr auto OverAligned = alignof(std::max_align_t) * 2;
28 int A_constructed = 0;
30 struct alignas(OverAligned) A {
31 A() { ++A_constructed;}
32 ~A() { --A_constructed;}
36 int B_constructed = 0;
38 struct alignas(std::max_align_t) B
40 std::max_align_t member;
41 B() { ++B_constructed;}
42 ~B() { --B_constructed;}
47 alignas(OverAligned) char DummyData[OverAligned * 4];
49 void* operator new[](std::size_t s, std::align_val_t a) TEST_THROW_SPEC(std::bad_alloc)
51 assert(new_called == 0); // We already allocated
52 assert(s <= sizeof(DummyData));
53 assert(static_cast<std::size_t>(a) == OverAligned);
58 void operator delete[](void* p, std::align_val_t) TEST_NOEXCEPT
60 assert(new_called == 1);
62 assert(p == DummyData);
71 assert(A_constructed == 3);
74 assert(!A_constructed);
80 assert(B_constructed == 3);