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 default unique_ptr<T[]> ctor 15 16// default unique_ptr<T[]> ctor shouldn't require complete type 17 18#include <memory> 19#include <cassert> 20 21struct A; 22 23class Deleter 24{ 25 int state_; 26 27 Deleter(Deleter&); 28 Deleter& operator=(Deleter&); 29 30public: 31 Deleter() : state_(5) {} 32 33 int state() const {return state_;} 34 35 void operator()(A* p); 36}; 37 38void check(int i); 39 40template <class D = std::default_delete<A> > 41struct B 42{ 43 std::unique_ptr<A[], D> a_; 44 B(); 45 ~B(); 46 47 A* get() const {return a_.get();} 48 D& get_deleter() {return a_.get_deleter();} 49}; 50 51int main() 52{ 53 { 54 B<> s; 55 assert(s.get() == 0); 56 } 57 check(0); 58 { 59 B<Deleter> s; 60 assert(s.get() == 0); 61 assert(s.get_deleter().state() == 5); 62 } 63 check(0); 64} 65 66struct A 67{ 68 static int count; 69 A() {++count;} 70 A(const A&) {++count;} 71 ~A() {--count;} 72}; 73 74int A::count = 0; 75 76void Deleter::operator()(A* p) {delete p;} 77 78void check(int i) 79{ 80 assert(A::count == i); 81} 82 83template <class D> 84B<D>::B() {} 85 86template <class D> 87B<D>::~B() {} 88