pointer.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <memory>
11
12// template<class Y> explicit shared_ptr(Y* p);
13
14#include <memory>
15#include <cassert>
16
17struct A
18{
19    static int count;
20
21    A() {++count;}
22    A(const A&) {++count;}
23    ~A() {--count;}
24};
25
26int A::count = 0;
27
28int main()
29{
30    {
31    A* ptr = new A;
32    std::shared_ptr<A> p(ptr);
33    assert(A::count == 1);
34    assert(p.use_count() == 1);
35    assert(p.get() == ptr);
36    }
37    assert(A::count == 0);
38    {
39    A* ptr = new A;
40    std::shared_ptr<void> p(ptr);
41    assert(A::count == 1);
42    assert(p.use_count() == 1);
43    assert(p.get() == ptr);
44    }
45    assert(A::count == 0);
46}
47