Home | History | Annotate | Download | only in unique.ptr.single.ctor
      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 ctor
     15 
     16 #include <memory>
     17 #include <cassert>
     18 
     19 #include "../../deleter.h"
     20 
     21 // test converting move ctor.  Should only require a MoveConstructible deleter, or if
     22 //    deleter is a reference, not even that.
     23 // Implicit version
     24 
     25 struct A
     26 {
     27     static int count;
     28     A() {++count;}
     29     A(const A&) {++count;}
     30     virtual ~A() {--count;}
     31 };
     32 
     33 int A::count = 0;
     34 
     35 struct B
     36     : public A
     37 {
     38     static int count;
     39     B() {++count;}
     40     B(const B&) {++count;}
     41     virtual ~B() {--count;}
     42 };
     43 
     44 int B::count = 0;
     45 
     46 int main()
     47 {
     48     std::unique_ptr<B, Deleter<B> > s(new B);
     49     std::unique_ptr<A, Deleter<A> > s2 = s;
     50 }
     51