OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This is a "No Compile Test" suite. | 5 // This is a "No Compile Test" suite. |
6 // http://dev.chromium.org/developers/testing/no-compile-tests | 6 // http://dev.chromium.org/developers/testing/no-compile-tests |
7 | 7 |
8 #include "base/callback_list.h" | 8 #include "base/callback_list.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 class Foo { | 17 class Foo { |
18 public: | 18 public: |
19 Foo() {} | 19 Foo() {} |
20 ~Foo() {} | 20 ~Foo() {} |
21 }; | 21 }; |
22 | 22 |
23 class FooListener { | 23 class FooListener { |
24 public: | 24 public: |
25 FooListener() {} | 25 FooListener() {} |
26 | 26 |
27 void GotAScopedFoo(scoped_ptr<Foo> f) { foo_ = f.Pass(); } | 27 void GotAScopedFoo(scoped_ptr<Foo> f) { foo_ = std::move(f); } |
dcheng
2015/12/31 10:24:53
#include <utility>
tzik
2015/12/31 11:10:46
Done.
| |
28 | 28 |
29 scoped_ptr<Foo> foo_; | 29 scoped_ptr<Foo> foo_; |
30 | 30 |
31 private: | 31 private: |
32 DISALLOW_COPY_AND_ASSIGN(FooListener); | 32 DISALLOW_COPY_AND_ASSIGN(FooListener); |
33 }; | 33 }; |
34 | 34 |
35 | 35 |
36 #if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to deleted constructor"] | 36 #if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to deleted constructor"] |
37 | 37 |
38 // Callbacks run with a move-only typed parameter. | 38 // Callbacks run with a move-only typed parameter. |
39 // | 39 // |
40 // CallbackList does not support move-only typed parameters. Notify() is | 40 // CallbackList does not support move-only typed parameters. Notify() is |
41 // designed to take zero or more parameters, and run each registered callback | 41 // designed to take zero or more parameters, and run each registered callback |
42 // with them. With move-only types, the parameter will be set to NULL after the | 42 // with them. With move-only types, the parameter will be set to NULL after the |
43 // first callback has been run. | 43 // first callback has been run. |
44 void WontCompile() { | 44 void WontCompile() { |
45 FooListener f; | 45 FooListener f; |
46 CallbackList<void(scoped_ptr<Foo>)> c1; | 46 CallbackList<void(scoped_ptr<Foo>)> c1; |
47 scoped_ptr<CallbackList<void(scoped_ptr<Foo>)>::Subscription> sub = | 47 scoped_ptr<CallbackList<void(scoped_ptr<Foo>)>::Subscription> sub = |
48 c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f))); | 48 c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f))); |
49 c1.Notify(scoped_ptr<Foo>(new Foo())); | 49 c1.Notify(scoped_ptr<Foo>(new Foo())); |
50 } | 50 } |
51 | 51 |
52 #endif | 52 #endif |
53 | 53 |
54 } // namespace base | 54 } // namespace base |
OLD | NEW |