1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // struct destroying_delete_t {
11 // explicit destroying_delete_t() = default;
13 // inline constexpr destroying_delete_t destroying_delete{};
15 // UNSUPPORTED: c++03, c++11, c++14, c++17
20 #include "test_macros.h"
28 void operator delete(A
*, std::destroying_delete_t
);
31 bool A_constructed
= false;
32 bool A_destroyed
= false;
33 bool A_destroying_deleted
= false;
44 return new(::operator new(sizeof(A
))) A();
47 void A::operator delete(A
* a
, std::destroying_delete_t
) {
48 A_destroying_deleted
= true;
52 // Only test the definition of the library feature-test macro when the compiler
53 // supports the feature -- otherwise we don't define the library feature-test
55 #if defined(__cpp_impl_destroying_delete)
56 # if !defined(__cpp_lib_destroying_delete)
57 # error "Expected __cpp_lib_destroying_delete to be defined"
58 # elif __cpp_lib_destroying_delete < 201806L
59 # error "Unexpected value of __cpp_lib_destroying_delete"
62 # if defined(__cpp_lib_destroying_delete)
63 # error "The library feature-test macro for destroying delete shouldn't be defined when the compiler doesn't support the language feature"
67 int main(int, char**) {
68 // Ensure that we call the destroying delete and not the destructor.
70 assert(A_constructed
);
73 assert(A_destroying_deleted
);