move_convert11.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 converting move ctor
15
16// test converting move ctor.  Should only require a MoveConstructible deleter, or if
17//    deleter is a reference, not even that.
18// Implicit version
19
20#include <memory>
21#include <cassert>
22
23#include "../../deleter.h"
24
25struct A
26{
27    static int count;
28    A() {++count;}
29    A(const A&) {++count;}
30    virtual ~A() {--count;}
31};
32
33int A::count = 0;
34
35struct B
36    : public A
37{
38    static int count;
39    B() {++count;}
40    B(const B&) {++count;}
41    virtual ~B() {--count;}
42};
43
44int B::count = 0;
45
46int main()
47{
48    {
49    const std::unique_ptr<B[], Deleter<B[]> > s(new B);
50    A* p = s.get();
51    std::unique_ptr<A[], Deleter<A[]> > s2 = s;
52    assert(s2.get() == p);
53    assert(s.get() == 0);
54    assert(A::count == 1);
55    assert(B::count == 1);
56    assert(s2.get_deleter().state() == 5);
57    assert(s.get_deleter().state() == 0);
58    }
59    assert(A::count == 0);
60    assert(B::count == 0);
61}
62