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: with_system_cxx_lib=macosx10.12
14 // XFAIL: with_system_cxx_lib=macosx10.11
15 // XFAIL: with_system_cxx_lib=macosx10.10
16 // XFAIL: with_system_cxx_lib=macosx10.9
17 // XFAIL: with_system_cxx_lib=macosx10.7
18 // XFAIL: with_system_cxx_lib=macosx10.8
20 // XFAIL: no-aligned-allocation
22 // On Windows libc++ doesn't provide its own definitions for new/delete
23 // but instead depends on the ones in VCRuntime. However VCRuntime does not
24 // yet provide aligned new/delete definitions so this test fails.
25 // XFAIL: LIBCXX-WINDOWS-FIXME
27 // test operator new nothrow by replacing only operator new
35 #include "test_macros.h"
37 constexpr auto OverAligned = alignof(std::max_align_t) * 2;
39 bool A_constructed = false;
41 struct alignas(OverAligned) A
43 A() {A_constructed = true;}
44 ~A() {A_constructed = false;}
47 bool B_constructed = false;
50 std::max_align_t member;
51 B() { B_constructed = true; }
52 ~B() { B_constructed = false; }
56 alignas(OverAligned) char Buff[OverAligned * 2];
58 void* operator new(std::size_t s, std::align_val_t a) TEST_THROW_SPEC(std::bad_alloc)
61 assert(s <= sizeof(Buff));
62 assert(static_cast<std::size_t>(a) == OverAligned);
67 void operator delete(void* p, std::align_val_t a) TEST_NOEXCEPT
70 assert(static_cast<std::size_t>(a) == OverAligned);
79 A* ap = new (std::nothrow) A;
81 assert(A_constructed);
84 assert(!A_constructed);
88 B* bp = new (std::nothrow) B;
90 assert(B_constructed);
94 assert(!B_constructed);