reset1.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// unique_ptr
13
14// test reset
15
16#include <memory>
17#include <cassert>
18
19struct A
20{
21    static int count;
22    A() {++count;}
23    A(const A&) {++count;}
24    ~A() {--count;}
25};
26
27int A::count = 0;
28
29int main()
30{
31    {
32    std::unique_ptr<A[]> p(new A[3]);
33    assert(A::count == 3);
34    A* i = p.get();
35    p.reset();
36    assert(A::count == 0);
37    assert(p.get() == 0);
38    }
39    assert(A::count == 0);
40    {
41    std::unique_ptr<A[]> p(new A[4]);
42    assert(A::count == 4);
43    A* i = p.get();
44    p.reset(new A[5]);
45    assert(A::count == 5);
46    }
47    assert(A::count == 0);
48}
49