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 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03
10 
11 // test_memory_resource requires RTTI for dynamic_cast
12 // UNSUPPORTED: no-rtti
13 
14 // <experimental/memory_resource>
15 
16 //------------------------------------------------------------------------------
17 // TESTING virtual ~memory_resource()
18 //
19 // Concerns:
20 //  A) 'memory_resource' is destructible.
21 //  B) The destructor is implicitly marked noexcept.
22 //  C) The destructor is marked virtual.
23 
24 #include <experimental/memory_resource>
25 #include <type_traits>
26 #include <cassert>
27 
28 #include "test_memory_resource.h"
29 
30 #include "test_macros.h"
31 
32 using std::experimental::pmr::memory_resource;
33 
main(int,char **)34 int main(int, char**)
35 {
36     static_assert(
37         std::has_virtual_destructor<memory_resource>::value
38       , "Must have virtual destructor"
39       );
40     static_assert(
41         std::is_nothrow_destructible<memory_resource>::value,
42         "Must be nothrow destructible"
43       );
44     static_assert(
45         std::is_abstract<memory_resource>::value
46       , "Must be abstract"
47       );
48     // Check that the destructor of `TestResource` is called when
49     // it is deleted as a pointer to `memory_resource`
50     {
51         using TR = TestResource;
52         memory_resource* M = new TR(42);
53         assert(TR::resource_alive == 1);
54         assert(TR::resource_constructed == 1);
55         assert(TR::resource_destructed == 0);
56 
57         delete M;
58 
59         assert(TR::resource_alive == 0);
60         assert(TR::resource_constructed == 1);
61         assert(TR::resource_destructed == 1);
62     }
63 
64   return 0;
65 }
66