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 // weak_ptr
13 
14 // bool expired() const;
15 
16 #include <memory>
17 #include <cassert>
18 
19 struct A
20 {
21     static int count;
22 
AA23     A() {++count;}
AA24     A(const A&) {++count;}
~AA25     ~A() {--count;}
26 };
27 
28 int A::count = 0;
29 
main()30 int main()
31 {
32     {
33         std::weak_ptr<A> wp;
34         assert(wp.use_count() == 0);
35         assert(wp.expired() == (wp.use_count() == 0));
36     }
37     {
38         std::shared_ptr<A> sp0(new A);
39         std::weak_ptr<A> wp(sp0);
40         assert(wp.use_count() == 1);
41         assert(wp.expired() == (wp.use_count() == 0));
42         sp0.reset();
43         assert(wp.use_count() == 0);
44         assert(wp.expired() == (wp.use_count() == 0));
45     }
46 }
47