[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / language.support / support.dynamic / destroying_delete_t.pass.cpp
blobae9feca42d09a7c39c4f45a3722d618d4c1f5903
1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 // struct destroying_delete_t {
11 // explicit destroying_delete_t() = default;
12 // };
13 // inline constexpr destroying_delete_t destroying_delete{};
15 // UNSUPPORTED: c++03, c++11, c++14, c++17
17 // UNSUPPORTED: apple-clang-9, apple-clang-10
18 // UNSUPPORTED: clang-6, clang-7
20 #include <new>
22 #include <cassert>
23 #include "test_macros.h"
25 struct A {
26 void *data;
27 A();
28 ~A();
30 static A* New();
31 void operator delete(A*, std::destroying_delete_t);
34 bool A_constructed = false;
35 bool A_destroyed = false;
36 bool A_destroying_deleted = false;
38 A::A() {
39 A_constructed = true;
42 A::~A() {
43 A_destroyed = true;
46 A* A::New() {
47 return new(::operator new(sizeof(A))) A();
50 void A::operator delete(A* a, std::destroying_delete_t) {
51 A_destroying_deleted = true;
52 ::operator delete(a);
55 // Only test the definition of the library feature-test macro when the compiler
56 // supports the feature -- otherwise we don't define the library feature-test
57 // macro.
58 #if defined(__cpp_impl_destroying_delete)
59 # if !defined(__cpp_lib_destroying_delete)
60 # error "Expected __cpp_lib_destroying_delete to be defined"
61 # elif __cpp_lib_destroying_delete < 201806L
62 # error "Unexpected value of __cpp_lib_destroying_delete"
63 # endif
64 #else
65 # if defined(__cpp_lib_destroying_delete)
66 # error "The library feature-test macro for destroying delete shouldn't be defined when the compiler doesn't support the language feature"
67 # endif
68 #endif
70 int main(int, char**) {
71 // Ensure that we call the destroying delete and not the destructor.
72 A* ap = A::New();
73 assert(A_constructed);
74 delete ap;
75 assert(!A_destroyed);
76 assert(A_destroying_deleted);
77 return 0;