1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // test placement new array
10 
11 #include <new>
12 #include <cassert>
13 
14 #include "test_macros.h"
15 
16 int A_constructed = 0;
17 
18 struct A
19 {
AA20     A() {++A_constructed;}
~AA21     ~A() {--A_constructed;}
22 };
23 
main(int,char **)24 int main(int, char**)
25 {
26     const std::size_t Size = 3;
27     // placement new might require additional space.
28     const std::size_t ExtraSize = 64;
29     char buf[Size*sizeof(A) + ExtraSize];
30 
31     A* ap = new(buf) A[Size];
32     assert((char*)ap >= buf);
33     assert((char*)ap < (buf + ExtraSize));
34     assert(A_constructed == Size);
35 
36   return 0;
37 }
38