nullptr_t_deleter_allocator_throw.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
13
14#include <memory>
15#include <cassert>
16#include "../test_deleter.h"
17#include "../test_allocator.h"
18
19struct A
20{
21    static int count;
22
23    A() {++count;}
24    A(const A&) {++count;}
25    ~A() {--count;}
26};
27
28int A::count = 0;
29
30int main()
31{
32    try
33    {
34        test_allocator<A>::throw_after = 0;
35        std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
36        assert(false);
37    }
38    catch (std::bad_alloc&)
39    {
40        assert(A::count == 0);
41        assert(test_deleter<A>::count == 0);
42        assert(test_deleter<A>::dealloc_count == 1);
43        assert(test_allocator<A>::count == 0);
44        assert(test_allocator<A>::alloc_count == 0);
45    }
46}
47