nullptr.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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 unique_ptr move assignment 15 16#include <memory> 17#include <cassert> 18 19// test assignment from null 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 31int main() 32{ 33 { 34 std::unique_ptr<A> s2(new A); 35 assert(A::count == 1); 36 s2 = nullptr; 37 assert(A::count == 0); 38 assert(s2.get() == 0); 39 } 40 assert(A::count == 0); 41} 42