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 int A_constructed = 0; 15 16 struct A 17 { 18 A() {++A_constructed;} 19 ~A() {--A_constructed;} 20 }; 21 22 int main() 23 { 24 char buf[sizeof(A)]; 25 26 A* ap = new(buf) A; 27 assert((char*)ap == buf); 28 assert(A_constructed == 1); 29 } 30