brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1006 B · 55be3f7 Raw
45 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// test placement new10 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_new32static_assert((test_direct_call(), true));33#endif34 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