libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

new_array.pass.cpp (834B)


      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 placement new array
     11 
     12 #include <new>
     13 #include <cassert>
     14 
     15 int A_constructed = 0;
     16 
     17 struct A
     18 {
     19     A() {++A_constructed;}
     20     ~A() {--A_constructed;}
     21 };
     22 
     23 int main()
     24 {
     25     const std::size_t Size = 3;
     26     // placement new might require additional space.
     27     const std::size_t ExtraSize = 64;
     28     char buf[Size*sizeof(A) + ExtraSize];
     29 
     30     A* ap = new(buf) A[Size];
     31     assert((char*)ap >= buf);
     32     assert((char*)ap < (buf + ExtraSize));
     33     assert(A_constructed == Size);
     34 }