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 // Test unique_ptr move assignment 14 15 #include <memory> 16 #include <cassert> 17 18 #include "unique_ptr_test_helper.h" 19 20 // test assignment from null 21 template <bool IsArray> 22 void test_basic() { 23 typedef typename std::conditional<IsArray, A[], A>::type VT; 24 const int expect_alive = IsArray ? 5 : 1; 25 { 26 std::unique_ptr<VT> s2(newValue<VT>(expect_alive)); 27 assert(A::count == expect_alive); 28 s2 = NULL; 29 assert(A::count == 0); 30 assert(s2.get() == 0); 31 } 32 assert(A::count == 0); 33 } 34 35 int main(int, char**) { 36 test_basic</*IsArray*/ false>(); 37 test_basic<true>(); 38 39 return 0; 40 } 41