[NFC][DirectX] Change deprecated insertBefore(Instruction*) API (#125308)
[llvm-project.git] / libcxx / test / std / language.support / support.dynamic / destroying_delete_t.pass.cpp
blob95d2c41d7bfebca409ea7b870886bb17f87e4c52
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 //===----------------------------------------------------------------------===//
9 // struct destroying_delete_t {
10 // explicit destroying_delete_t() = default;
11 // };
12 // inline constexpr destroying_delete_t destroying_delete{};
14 // UNSUPPORTED: c++03, c++11, c++14, c++17
16 #include <new>
18 #include <cassert>
19 #include "test_macros.h"
21 struct A {
22 void *data;
23 A();
24 ~A();
26 static A* New();
27 void operator delete(A*, std::destroying_delete_t);
30 bool A_constructed = false;
31 bool A_destroyed = false;
32 bool A_destroying_deleted = false;
34 A::A() {
35 A_constructed = true;
38 A::~A() {
39 A_destroyed = true;
42 A* A::New() {
43 return new(::operator new(sizeof(A))) A();
46 void A::operator delete(A* a, std::destroying_delete_t) {
47 A_destroying_deleted = true;
48 ::operator delete(a);
51 // Only test the definition of the library feature-test macro when the compiler
52 // supports the feature -- otherwise we don't define the library feature-test
53 // macro.
54 #if defined(__cpp_impl_destroying_delete)
55 # if !defined(__cpp_lib_destroying_delete)
56 # error "Expected __cpp_lib_destroying_delete to be defined"
57 # elif __cpp_lib_destroying_delete < 201806L
58 # error "Unexpected value of __cpp_lib_destroying_delete"
59 # endif
60 #else
61 # if defined(__cpp_lib_destroying_delete)
62 # error "The library feature-test macro for destroying delete shouldn't be defined when the compiler doesn't support the language feature"
63 # endif
64 #endif
66 int main(int, char**) {
67 // Ensure that we call the destroying delete and not the destructor.
68 A* ap = A::New();
69 assert(A_constructed);
70 delete ap;
71 assert(!A_destroyed);
72 assert(A_destroying_deleted);
73 return 0;