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 // <experimental/memory_resource>
10 
11 // UNSUPPORTED: c++98, c++03
12 
13 //------------------------------------------------------------------------------
14 // TESTING void * memory_resource::deallocate(void *, size_t, size_t = max_align)
15 //
16 // Concerns:
17 //  A) 'memory_resource' contains a member 'deallocate' with the required
18 //     signature, including the default alignment parameter.
19 //  B) The return type of 'deallocate' is 'void'.
20 //  C) 'deallocate' is not marked as 'noexcept'.
21 //  D) Invoking 'deallocate' invokes 'do_deallocate' with the same arguments.
22 
23 
24 #include <experimental/memory_resource>
25 #include <type_traits>
26 #include <cstddef>
27 #include <cassert>
28 
29 #include "test_memory_resource.h"
30 
31 #include "test_macros.h"
32 
33 using std::experimental::pmr::memory_resource;
34 
main(int,char **)35 int main(int, char**)
36 {
37     NullResource R(42);
38     auto& P = R.getController();
39     memory_resource& M = R;
40     {
41         static_assert(
42             std::is_same<decltype(M.deallocate(nullptr, 0, 0)), void>::value
43           , "Must be void"
44           );
45         static_assert(
46             std::is_same<decltype(M.deallocate(nullptr, 0)), void>::value
47           , "Must be void"
48           );
49     }
50     {
51         static_assert(
52             ! noexcept(M.deallocate(nullptr, 0, 0))
53           , "Must not be noexcept."
54           );
55         static_assert(
56             ! noexcept(M.deallocate(nullptr, 0))
57           , "Must not be noexcept."
58           );
59     }
60     {
61         int s = 100;
62         int a = 64;
63         void* p = reinterpret_cast<void*>(640);
64         M.deallocate(p, s, a);
65         assert(P.dealloc_count == 1);
66         assert(P.checkDealloc(p, s, a));
67 
68         s = 128;
69         a = alignof(std::max_align_t);
70         p = reinterpret_cast<void*>(12800);
71         M.deallocate(p, s);
72         assert(P.dealloc_count == 2);
73         assert(P.checkDealloc(p, s, a));
74     }
75 
76   return 0;
77 }
78