brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 1b5a095 Raw
60 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <memory>10 11// template <class X> class auto_ptr;12 13// void reset(X* p=0) throw();14 15// REQUIRES: c++03 || c++11 || c++1416// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS17 18#include <memory>19#include <cassert>20 21#include "test_macros.h"22#include "../A.h"23 24void25test()26{27    {28    A* p = new A(1);29    std::auto_ptr<A> ap(p);30    ap.reset();31    assert(ap.get() == 0);32    assert(A::count == 0);33    }34    assert(A::count == 0);35    {36    A* p = new A(1);37    std::auto_ptr<A> ap(p);38    ap.reset(p);39    assert(ap.get() == p);40    assert(A::count == 1);41    }42    assert(A::count == 0);43    {44    A* p = new A(1);45    std::auto_ptr<A> ap(p);46    A* p2 = new A(2);47    ap.reset(p2);48    assert(ap.get() == p2);49    assert(A::count == 1);50    }51    assert(A::count == 0);52}53 54int main(int, char**)55{56    test();57 58  return 0;59}60