Home | History | Annotate | Download | only in support.dynamic
      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 relevent 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 // XFAIL: with_system_cxx_lib=macosx10.12
     20 // XFAIL: with_system_cxx_lib=macosx10.11
     21 // XFAIL: with_system_cxx_lib=macosx10.10
     22 // XFAIL: with_system_cxx_lib=macosx10.9
     23 // XFAIL: with_system_cxx_lib=macosx10.7
     24 // XFAIL: with_system_cxx_lib=macosx10.8
     25 
     26 // RUN: %build -faligned-allocation
     27 // RUN: %run
     28 
     29 #include <new>
     30 #include <typeinfo>
     31 #include <string>
     32 #include <cassert>
     33 
     34 #include "test_macros.h"
     35 
     36 int main() {
     37   {
     38     static_assert(std::is_enum<std::align_val_t>::value, "");
     39     typedef std::underlying_type<std::align_val_t>::type UT;
     40     static_assert((std::is_same<UT, std::size_t>::value), "");
     41   }
     42   {
     43     static_assert((!std::is_constructible<std::align_val_t, std::size_t>::value), "");
     44 #if TEST_STD_VER >= 11
     45     static_assert(!std::is_constructible<std::size_t, std::align_val_t>::value, "");
     46 #else
     47     static_assert((std::is_constructible<std::size_t, std::align_val_t>::value), "");
     48 #endif
     49   }
     50   {
     51     std::align_val_t a = std::align_val_t(0);
     52     std::align_val_t b = std::align_val_t(32);
     53     assert(a != b);
     54     assert(a == std::align_val_t(0));
     55     assert(b == std::align_val_t(32));
     56   }
     57   {
     58     void *ptr = ::operator new(1, std::align_val_t(128));
     59     assert(ptr);
     60     assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0);
     61     ::operator delete(ptr, std::align_val_t(128));
     62   }
     63   {
     64     void *ptr = ::operator new(1, std::align_val_t(128), std::nothrow);
     65     assert(ptr);
     66     assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0);
     67     ::operator delete(ptr, std::align_val_t(128), std::nothrow);
     68   }
     69   {
     70     void *ptr = ::operator new[](1, std::align_val_t(128));
     71     assert(ptr);
     72     assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0);
     73     ::operator delete[](ptr, std::align_val_t(128));
     74   }
     75   {
     76     void *ptr = ::operator new[](1, std::align_val_t(128), std::nothrow);
     77     assert(ptr);
     78     assert(reinterpret_cast<std::uintptr_t>(ptr) % 128 == 0);
     79     ::operator delete[](ptr, std::align_val_t(128), std::nothrow);
     80   }
     81 #ifndef TEST_HAS_NO_RTTI
     82   {
     83     // Check that libc++ doesn't define align_val_t in a versioning namespace.
     84     // And that it mangles the same in C++03 through C++17
     85     assert(typeid(std::align_val_t).name() == std::string("St11align_val_t"));
     86   }
     87 #endif
     88 }
     89