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 nothrow by replacing only operator new
23 #include "test_macros.h"
25 constexpr auto OverAligned = alignof(std::max_align_t) * 2;
27 int A_constructed = 0;
29 struct alignas(OverAligned) A
31 A() {++A_constructed;}
32 ~A() {--A_constructed;}
35 int B_constructed = 0;
38 std::max_align_t member;
39 B() { ++B_constructed; }
40 ~B() { --B_constructed; }
44 alignas(OverAligned) char Buff[OverAligned * 3];
46 void* operator new[](std::size_t s, std::align_val_t a) TEST_THROW_SPEC(std::bad_alloc)
49 assert(s <= sizeof(Buff));
50 assert(static_cast<std::size_t>(a) == OverAligned);
55 void operator delete[](void* p, std::align_val_t a) TEST_NOEXCEPT
58 assert(static_cast<std::size_t>(a) == OverAligned);
66 A* ap = new (std::nothrow) A[2];
68 assert(A_constructed == 2);
71 assert(A_constructed == 0);
75 B* bp = new (std::nothrow) B[2];
77 assert(B_constructed == 2);
81 assert(!B_constructed);