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 // Aligned allocation was not provided before macosx10.12 and as a result we
13 // get availability errors when the deployment target is older than macosx10.13.
14 // However, AppleClang 10 (and older) don't trigger availability errors.
15 // XFAIL: !(apple-clang-9 || apple-clang-10) && availability=macosx10.12
16 // XFAIL: !(apple-clang-9 || apple-clang-10) && availability=macosx10.11
17 // XFAIL: !(apple-clang-9 || apple-clang-10) && availability=macosx10.10
18 // XFAIL: !(apple-clang-9 || apple-clang-10) && availability=macosx10.9
19 // XFAIL: !(apple-clang-9 || apple-clang-10) && availability=macosx10.8
20 // XFAIL: !(apple-clang-9 || apple-clang-10) && availability=macosx10.7
22 // On AppleClang 10 (and older), instead of getting an availability failure
23 // like above, we get a link error when we link against a dylib that does
24 // not export the aligned allocation functions.
25 // XFAIL: (apple-clang-9 || apple-clang-10) && with_system_cxx_lib=macosx10.12
26 // XFAIL: (apple-clang-9 || apple-clang-10) && with_system_cxx_lib=macosx10.11
27 // XFAIL: (apple-clang-9 || apple-clang-10) && with_system_cxx_lib=macosx10.10
28 // XFAIL: (apple-clang-9 || apple-clang-10) && with_system_cxx_lib=macosx10.9
29 // XFAIL: (apple-clang-9 || apple-clang-10) && with_system_cxx_lib=macosx10.8
30 // XFAIL: (apple-clang-9 || apple-clang-10) && with_system_cxx_lib=macosx10.7
32 // asan and msan will not call the new handler.
33 // UNSUPPORTED: sanitizer-new-delete
35 // FIXME turn this into an XFAIL
36 // UNSUPPORTED: no-aligned-allocation && !gcc
38 // On Windows libc++ doesn't provide its own definitions for new/delete
39 // but instead depends on the ones in VCRuntime. However VCRuntime does not
40 // yet provide aligned new/delete definitions so this test fails to compile/link.
41 // XFAIL: LIBCXX-WINDOWS-FIXME
43 // test operator new (nothrow)
51 #include "test_macros.h"
53 constexpr auto OverAligned = __STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2;
55 int new_handler_called = 0;
60 std::set_new_handler(0);
63 bool A_constructed = false;
65 struct alignas(OverAligned) A
67 A() {A_constructed = true;}
68 ~A() {A_constructed = false;}
71 void test_max_alloc() {
72 std::set_new_handler(my_new_handler);
74 void* vp = operator new (std::numeric_limits<std::size_t>::max(),
75 std::align_val_t(OverAligned),
77 assert(new_handler_called == 1);
80 #ifndef TEST_HAS_NO_EXCEPTIONS
97 A* ap = new(std::nothrow) A;
99 assert(reinterpret_cast<std::uintptr_t>(ap) % OverAligned == 0);
100 assert(A_constructed);
102 assert(!A_constructed);