OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
| 8 #include <vector> |
8 | 9 |
9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // Used to test depth subtyping. | 17 // Used to test depth subtyping. |
17 class ConDecLoggerParent { | 18 class ConDecLoggerParent { |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 a->b.reset(new StructB); | 710 a->b.reset(new StructB); |
710 a->b->a.reset(a); | 711 a->b->a.reset(a); |
711 | 712 |
712 // Break the cycle by calling reset(). This will cause |a| (and hence, |a.b|) | 713 // Break the cycle by calling reset(). This will cause |a| (and hence, |a.b|) |
713 // to be deleted before the call to reset() returns. This tests that the | 714 // to be deleted before the call to reset() returns. This tests that the |
714 // implementation of scoped_ptr::reset() doesn't access |this| after it | 715 // implementation of scoped_ptr::reset() doesn't access |this| after it |
715 // deletes the underlying pointer. This behaviour is consistent with the | 716 // deletes the underlying pointer. This behaviour is consistent with the |
716 // definition of unique_ptr::reset in C++11. | 717 // definition of unique_ptr::reset in C++11. |
717 a->b.reset(); | 718 a->b.reset(); |
718 } | 719 } |
| 720 |
| 721 template<typename T> |
| 722 class ScopedPtr2 { |
| 723 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedPtr2) |
| 724 public: |
| 725 explicit ScopedPtr2(T* p) : p_(p) { } |
| 726 ~ScopedPtr2() { delete p_; } |
| 727 |
| 728 ScopedPtr2(ScopedPtr2&& rhs) : p_(nullptr) { |
| 729 using std::swap; |
| 730 swap(p_, rhs.p_); |
| 731 } |
| 732 |
| 733 ScopedPtr2& operator=(ScopedPtr2&& rhs) { |
| 734 using std::swap; |
| 735 swap(p_, rhs.p_); |
| 736 } |
| 737 |
| 738 private: |
| 739 T* p_; |
| 740 }; |
| 741 |
| 742 TEST(ScopedPtrTest, VectorOfScopedPtrs) { |
| 743 class TestClassPleaseIgnore { |
| 744 }; |
| 745 std::vector<ScopedPtr2<TestClassPleaseIgnore>> x; |
| 746 x.push_back(ScopedPtr2<TestClassPleaseIgnore>(new TestClassPleaseIgnore)); |
| 747 } |
OLD | NEW |