Home | History | Annotate | Download | only in unique.ptr.runtime
      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 converting move assignment
     15 
     16 #include <memory>
     17 #include <utility>
     18 #include <cassert>
     19 
     20 // Can't assign from const lvalue
     21 
     22 struct A
     23 {
     24     static int count;
     25     A() {++count;}
     26     A(const A&) {++count;}
     27     virtual ~A() {--count;}
     28 };
     29 
     30 int A::count = 0;
     31 
     32 struct B
     33     : public A
     34 {
     35     static int count;
     36     B() {++count;}
     37     B(const B&) {++count;}
     38     virtual ~B() {--count;}
     39 };
     40 
     41 int B::count = 0;
     42 
     43 int main()
     44 {
     45     {
     46     const boost::unique_ptr<B[]> s(new B);
     47     A* p = s.get();
     48     boost::unique_ptr<A[]> s2;
     49     s2 = s;
     50     assert(s2.get() == p);
     51     assert(s.get() == 0);
     52     assert(A::count == 1);
     53     assert(B::count == 1);
     54     }
     55     assert(A::count == 0);
     56     assert(B::count == 0);
     57 }
     58