new_faligned_allocation.sh.cpp (3137B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // test libc++'s implementation of align_val_t, and the relevant new/delete 11 // overloads in all dialects when -faligned-allocation is present. 12 13 // Libc++ defers to the underlying MSVC library to provide the new/delete 14 // definitions, which does not yet provide aligned allocation 15 // XFAIL: LIBCXX-WINDOWS-FIXME 16 17 // REQUIRES: -faligned-allocation 18 19 // The dylibs shipped before macosx10.14 do not contain the aligned allocation 20 // functions, so trying to force using those with -faligned-allocation results 21 // in a link error. 22 // XFAIL: with_system_cxx_lib=macosx10.13 23 // XFAIL: with_system_cxx_lib=macosx10.12 24 // XFAIL: with_system_cxx_lib=macosx10.11 25 // XFAIL: with_system_cxx_lib=macosx10.10 26 // XFAIL: with_system_cxx_lib=macosx10.9 27 // XFAIL: with_system_cxx_lib=macosx10.8 28 // XFAIL: with_system_cxx_lib=macosx10.7 29 30 // RUN: %build -faligned-allocation 31 // RUN: %run 32 33 #include <new> 34 #include <typeinfo> 35 #include <string> 36 #include <cassert> 37 38 #include "test_macros.h" 39 40 int main() { 41 { 42 static_assert(std::is_enum<std::align_val_t>::value, ""); 43 typedef std::underlying_type<std::align_val_t>::type UT; 44 static_assert((std::is_same<UT, std::size_t>::value), ""); 45 } 46 { 47 static_assert((!std::is_constructible<std::align_val_t, std::size_t>::value), ""); 48 #if TEST_STD_VER >= 11 49 static_assert(!std::is_constructible<std::size_t, std::align_val_t>::value, ""); 50 #else 51 static_assert((std::is_constructible<std::size_t, std::align_val_t>::value), ""); 52 #endif 53 } 54 { 55 std::align_val_t a = std::align_val_t(0); 56 std::align_val_t b = std::align_val_t(32); 57 assert(a != b); 58 assert(a == std::align_val_t(0)); 59 assert(b == std::align_val_t(32)); 60 } 61 { 62 void *ptr = ::operator new(1, std::align_val_t(128)); 63 assert(ptr); 64 assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0); 65 ::operator delete(ptr, std::align_val_t(128)); 66 } 67 { 68 void *ptr = ::operator new(1, std::align_val_t(128), std::nothrow); 69 assert(ptr); 70 assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0); 71 ::operator delete(ptr, std::align_val_t(128), std::nothrow); 72 } 73 { 74 void *ptr = ::operator new[](1, std::align_val_t(128)); 75 assert(ptr); 76 assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0); 77 ::operator delete[](ptr, std::align_val_t(128)); 78 } 79 { 80 void *ptr = ::operator new[](1, std::align_val_t(128), std::nothrow); 81 assert(ptr); 82 assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0); 83 ::operator delete[](ptr, std::align_val_t(128), std::nothrow); 84 } 85 #ifndef TEST_HAS_NO_RTTI 86 { 87 // Check that libc++ doesn't define align_val_t in a versioning namespace. 88 // And that it mangles the same in C++03 through C++17 89 assert(typeid(std::align_val_t).name() == std::string("St11align_val_t")); 90 } 91 #endif 92 }