1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <memory>
11 
12 // unique_ptr
13 
14 // Test unique_ptr(pointer, deleter) ctor
15 
16 // unique_ptr(pointer, deleter) should not work with derived pointers
17 
18 #include <memory>
19 #include <cassert>
20 
21 struct A
22 {
23     static int count;
AA24     A() {++count;}
AA25     A(const A&) {++count;}
~AA26     virtual ~A() {--count;}
27 };
28 
29 int A::count = 0;
30 
31 struct B
32     : public A
33 {
34     static int count;
BB35     B() {++count;}
BB36     B(const B&) {++count;}
~BB37     virtual ~B() {--count;}
38 };
39 
40 int B::count = 0;
41 
42 class Deleter
43 {
44     int state_;
45 
46 public:
Deleter()47     Deleter() : state_(5) {}
48 
state() const49     int state() const {return state_;}
50 
operator ()(A * p)51     void operator()(A* p) {delete [] p;}
52 };
53 
main()54 int main()
55 {
56     B* p = new B[3];
57     std::unique_ptr<A[], Deleter> s(p, Deleter());
58 }
59