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// <memory>
11
12// allocator:
13// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
14
15#include <memory>
16#include <cassert>
17
18#include "count_new.hpp"
19
20int A_constructed = 0;
21
22struct A
23{
24    int data;
25    A() {++A_constructed;}
26    A(const A&) {++A_constructed;}
27    ~A() {--A_constructed;}
28};
29
30int main()
31{
32    std::allocator<A> a;
33    assert(globalMemCounter.checkOutstandingNewEq(0));
34    assert(A_constructed == 0);
35    globalMemCounter.last_new_size = 0;
36    A* ap = a.allocate(3);
37    assert(globalMemCounter.checkOutstandingNewEq(1));
38    assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
39    assert(A_constructed == 0);
40    a.deallocate(ap, 3);
41    assert(globalMemCounter.checkOutstandingNewEq(0));
42    assert(A_constructed == 0);
43
44    globalMemCounter.last_new_size = 0;
45    A* ap2 = a.allocate(3, (const void*)5);
46    assert(globalMemCounter.checkOutstandingNewEq(1));
47    assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
48    assert(A_constructed == 0);
49    a.deallocate(ap2, 3);
50    assert(globalMemCounter.checkOutstandingNewEq(0));
51    assert(A_constructed == 0);
52}
53