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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Used to test depth subtyping. | 14 // Used to test depth subtyping. |
15 class ConDecLoggerParent { | 15 class ConDecLoggerParent { |
16 public: | 16 public: |
17 virtual ~ConDecLoggerParent() {} | 17 virtual ~ConDecLoggerParent() {} |
18 | 18 |
19 virtual void SetPtr(int* ptr) = 0; | 19 virtual void SetPtr(int* ptr) = 0; |
20 | 20 |
21 virtual int SomeMeth(int x) const = 0; | 21 virtual int SomeMeth(int x) const = 0; |
22 }; | 22 }; |
23 | 23 |
24 class ConDecLogger : public ConDecLoggerParent { | 24 class ConDecLogger : public ConDecLoggerParent { |
25 public: | 25 public: |
26 ConDecLogger() : ptr_(NULL) { } | 26 ConDecLogger() : ptr_(NULL) { } |
27 explicit ConDecLogger(int* ptr) { SetPtr(ptr); } | 27 explicit ConDecLogger(int* ptr) { SetPtr(ptr); } |
28 virtual ~ConDecLogger() { --*ptr_; } | 28 virtual ~ConDecLogger() { --*ptr_; } |
29 | 29 |
30 virtual void SetPtr(int* ptr) OVERRIDE { ptr_ = ptr; ++*ptr_; } | 30 void SetPtr(int* ptr) override { |
| 31 ptr_ = ptr; |
| 32 ++*ptr_; |
| 33 } |
31 | 34 |
32 virtual int SomeMeth(int x) const OVERRIDE { return x; } | 35 int SomeMeth(int x) const override { return x; } |
33 | 36 |
34 private: | 37 private: |
35 int* ptr_; | 38 int* ptr_; |
36 | 39 |
37 DISALLOW_COPY_AND_ASSIGN(ConDecLogger); | 40 DISALLOW_COPY_AND_ASSIGN(ConDecLogger); |
38 }; | 41 }; |
39 | 42 |
40 struct CountingDeleter { | 43 struct CountingDeleter { |
41 explicit CountingDeleter(int* count) : count_(count) {} | 44 explicit CountingDeleter(int* count) : count_(count) {} |
42 inline void operator()(double* ptr) const { | 45 inline void operator()(double* ptr) const { |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 scoped_ptr<Sub> sub2(new Sub); | 652 scoped_ptr<Sub> sub2(new Sub); |
650 | 653 |
651 // Upcast with Pass() works. | 654 // Upcast with Pass() works. |
652 scoped_ptr<Super> super1 = sub1.Pass(); | 655 scoped_ptr<Super> super1 = sub1.Pass(); |
653 super1 = sub2.Pass(); | 656 super1 = sub2.Pass(); |
654 | 657 |
655 // Upcast with an rvalue works. | 658 // Upcast with an rvalue works. |
656 scoped_ptr<Super> super2 = SubClassReturn(); | 659 scoped_ptr<Super> super2 = SubClassReturn(); |
657 super2 = SubClassReturn(); | 660 super2 = SubClassReturn(); |
658 } | 661 } |
OLD | NEW |