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 10 11 #include <new> 12 #include <cassert> 13 14 #include "test_macros.h" 15 16 int A_constructed = 0; 17 18 struct A 19 { 20 A() {++A_constructed;} 21 ~A() {--A_constructed;} 22 }; 23 24 int main(int, char**) 25 { 26 char buf[sizeof(A)]; 27 28 A* ap = new(buf) A; 29 assert((char*)ap == buf); 30 assert(A_constructed == 1); 31 32 return 0; 33 } 34