blob: 4220993a5fd11ed02060d9ab5550e3a2b969303c [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// <memory>
11
12// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
13
14#include <memory>
15#include <cassert>
16#include "../test_deleter.h"
Marshall Clow1b921882013-12-03 00:18:10 +000017#include "test_allocator.h"
Howard Hinnantc52f43e2010-08-22 00:59:46 +000018
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 A* ptr = new A;
33 try
34 {
35 test_allocator<A>::throw_after = 0;
36 std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
37 assert(false);
38 }
39 catch (std::bad_alloc&)
40 {
41 assert(A::count == 0);
42 assert(test_deleter<A>::count == 0);
43 assert(test_deleter<A>::dealloc_count == 1);
44 assert(test_allocator<A>::count == 0);
45 assert(test_allocator<A>::alloc_count == 0);
46 }
47}