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 // UNSUPPORTED: c++03 10 11 // <memory> 12 13 // unique_ptr 14 15 // FIXME(EricWF): This test contains tests for constructing a unique_ptr from NULL. 16 // The behavior demonstrated in this test is not meant to be standard; It simply 17 // tests the current status quo in libc++. 18 19 #include <memory> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "unique_ptr_test_helper.h" 24 25 template <class VT> 26 void test_pointer_ctor() { 27 { 28 std::unique_ptr<VT> p(0); 29 assert(p.get() == 0); 30 } 31 { 32 std::unique_ptr<VT, Deleter<VT> > p(0); 33 assert(p.get() == 0); 34 assert(p.get_deleter().state() == 0); 35 } 36 } 37 38 template <class VT> 39 void test_pointer_deleter_ctor() { 40 { 41 std::default_delete<VT> d; 42 std::unique_ptr<VT> p(0, d); 43 assert(p.get() == 0); 44 } 45 { 46 std::unique_ptr<VT, Deleter<VT> > p(0, Deleter<VT>(5)); 47 assert(p.get() == 0); 48 assert(p.get_deleter().state() == 5); 49 } 50 { 51 NCDeleter<VT> d(5); 52 std::unique_ptr<VT, NCDeleter<VT>&> p(0, d); 53 assert(p.get() == 0); 54 assert(p.get_deleter().state() == 5); 55 } 56 { 57 NCConstDeleter<VT> d(5); 58 std::unique_ptr<VT, NCConstDeleter<VT> const&> p(0, d); 59 assert(p.get() == 0); 60 assert(p.get_deleter().state() == 5); 61 } 62 } 63 64 int main(int, char**) { 65 { 66 // test_pointer_ctor<int>(); 67 test_pointer_deleter_ctor<int>(); 68 } 69 { 70 test_pointer_ctor<int[]>(); 71 test_pointer_deleter_ctor<int[]>(); 72 } 73 74 return 0; 75 } 76