1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // struct destroying_delete_t {
10 // explicit destroying_delete_t() = default;
12 // inline constexpr destroying_delete_t destroying_delete{};
14 // UNSUPPORTED: c++03, c++11, c++14, c++17
19 #include "test_macros.h"
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;
43 return new(::operator new(sizeof(A
))) A();
46 void A::operator delete(A
* a
, std::destroying_delete_t
) {
47 A_destroying_deleted
= true;
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
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"
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"
66 int main(int, char**) {
67 // Ensure that we call the destroying delete and not the destructor.
69 assert(A_constructed
);
72 assert(A_destroying_deleted
);