reset2.fail.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    virtual ~A() {--count;}
25};
26
27int A::count = 0;
28
29struct B
30    : public A
31{
32    static int count;
33    B() {++count;}
34    B(const B&) {++count;}
35    virtual ~B() {--count;}
36};
37
38int B::count = 0;
39
40int main()
41{
42    {
43    std::unique_ptr<A[]> p(new A);
44    assert(A::count == 1);
45    assert(B::count == 0);
46    A* i = p.get();
47    p.reset(new B);
48    assert(A::count == 1);
49    assert(B::count == 1);
50    }
51    assert(A::count == 0);
52    assert(B::count == 0);
53    {
54    std::unique_ptr<A[]> p(new B);
55    assert(A::count == 1);
56    assert(B::count == 1);
57    A* i = p.get();
58    p.reset(new B);
59    assert(A::count == 1);
60    assert(B::count == 1);
61    }
62    assert(A::count == 0);
63    assert(B::count == 0);
64}
65