move03.fail.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
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 unique_ptr move assignment
15
16#include <memory>
17#include <cassert>
18
19// Can't copy from lvalue
20
21struct A
22{
23    static int count;
24    A() {++count;}
25    A(const A&) {++count;}
26    ~A() {--count;}
27};
28
29int A::count = 0;
30
31class Deleter
32{
33    int state_;
34
35public:
36
37    Deleter() : state_(5) {}
38
39    int state() const {return state_;}
40
41    void operator()(A* p) {delete p;}
42};
43
44int main()
45{
46    {
47    std::unique_ptr<A, Deleter> s(new A);
48    A* p = s.get();
49    std::unique_ptr<A, Deleter> s2;
50    s2 = s;
51    assert(s2.get() == p);
52    assert(s.get() == 0);
53    assert(A::count == 1);
54    }
55    assert(A::count == 0);
56}
57