[lld][WebAssembly] Add `--table-base` setting
[llvm-project.git] / libcxx / test / std / language.support / support.dynamic / destroying_delete_t.pass.cpp
blob7f52e2d8d50800c6e7ce01ac7517a9bac51bce0e
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 #include <new>
19 #include <cassert>
20 #include "test_macros.h"
22 struct A {
23 void *data;
24 A();
25 ~A();
27 static A* New();
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;
35 A::A() {
36 A_constructed = true;
39 A::~A() {
40 A_destroyed = true;
43 A* A::New() {
44 return new(::operator new(sizeof(A))) A();
47 void A::operator delete(A* a, std::destroying_delete_t) {
48 A_destroying_deleted = true;
49 ::operator delete(a);
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
54 // macro.
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"
60 # endif
61 #else
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"
64 # endif
65 #endif
67 int main(int, char**) {
68 // Ensure that we call the destroying delete and not the destructor.
69 A* ap = A::New();
70 assert(A_constructed);
71 delete ap;
72 assert(!A_destroyed);
73 assert(A_destroying_deleted);
74 return 0;