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