1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <memory> 10 11 // unique_ptr 12 13 // The deleter is not called if get() == 0 14 15 #include <memory> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 class Deleter { 21 int state_; 22 23 Deleter(Deleter&); 24 Deleter& operator=(Deleter&); 25 26 public: Deleter()27 Deleter() : state_(0) {} 28 state() const29 int state() const { return state_; } 30 operator ()(void *)31 void operator()(void*) { ++state_; } 32 }; 33 34 template <class T> test_basic()35void test_basic() { 36 Deleter d; 37 assert(d.state() == 0); 38 { 39 std::unique_ptr<T, Deleter&> p(nullptr, d); 40 assert(p.get() == nullptr); 41 assert(&p.get_deleter() == &d); 42 } 43 assert(d.state() == 0); 44 } 45 main(int,char **)46int main(int, char**) { 47 test_basic<int>(); 48 test_basic<int[]>(); 49 50 return 0; 51 } 52