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// <memory>
10
11// template <class Alloc>
12// struct allocator_traits
13// {
14// static constexpr void deallocate(allocator_type& a, pointer p, size_type n);
15// ...
16// };
17
18#include <memory>
19#include <cassert>
20#include <cstddef>
21
22#include "test_macros.h"
23#include "incomplete_type_helper.h"
24
25template <class T>
26struct A
27{
28 typedef T value_type;
29
30 TEST_CONSTEXPR_CXX20 A(int& called) : called_(called) {}
31
32 TEST_CONSTEXPR_CXX20 void deallocate(value_type* p, std::size_t n)
33 {
34 assert(p == &storage);
35 assert(n == 10);
36 ++called_;
37 }
38
39 int& called_;
40
41 value_type storage;
42};
43
44TEST_CONSTEXPR_CXX20 bool test()
45{
46 {
47 int called = 0;
48 A<int> a(called);
49 std::allocator_traits<A<int> >::deallocate(a&: a, p: &a.storage, n: 10);
50 assert(called == 1);
51 }
52 {
53 int called = 0;
54 typedef A<IncompleteHolder*> Alloc;
55 Alloc a(called);
56 std::allocator_traits<Alloc>::deallocate(a&: a, p: &a.storage, n: 10);
57 assert(called == 1);
58 }
59
60 return true;
61}
62
63int main(int, char**)
64{
65 test();
66#if TEST_STD_VER > 17
67 static_assert(test());
68#endif
69 return 0;
70}
71

source code of libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp