pointer_deleter04.fail.cpp revision c52f43e72dfcea03037729649da84c23b3beb04a
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(pointer, deleter) ctor 15 16// unique_ptr<T, const D&>(pointer, D()) should not compile 17 18#include <memory> 19#include <cassert> 20 21struct A 22{ 23 static int count; 24 A() {++count;} 25 A(const A&) {++count;} 26 ~A() {--count;} 27}; 28 29int A::count = 0; 30 31class Deleter 32{ 33 int state_; 34 35public: 36 37 Deleter() : state_(5) {} 38 39 int state() const {return state_;} 40 void set_state(int s) {state_ = s;} 41 42 void operator()(A* p) const {delete [] p;} 43}; 44 45int main() 46{ 47 { 48 A* p = new A[3]; 49 assert(A::count == 3); 50 std::unique_ptr<A[], const Deleter&> s(p, Deleter()); 51 assert(s.get() == p); 52 assert(s.get_deleter().state() == 5); 53 } 54 assert(A::count == 0); 55} 56