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
16int A_constructed = 0;
17
18struct A {
19 A() { ++A_constructed; }
20 ~A() { --A_constructed; }
21};
22
23TEST_CONSTEXPR_OPERATOR_NEW void test_direct_call() {
24 assert(::operator new(sizeof(int), &A_constructed) == &A_constructed);
25
26 char ch = '*';
27 assert(::operator new(1, &ch) == &ch);
28 assert(ch == '*');
29}
30
31#ifdef __cpp_lib_constexpr_new
32static_assert((test_direct_call(), true));
33#endif
34
35int main(int, char**) {
36 char buf[sizeof(A)];
37
38 A* ap = new (buf) A;
39 assert((char*)ap == buf);
40 assert(A_constructed == 1);
41
42 test_direct_call();
43 return 0;
44}
45

source code of libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new.pass.cpp