[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
scheib | 0411d8f7 | 2015-10-19 19:29:55 | [diff] [blame] | 5 | // This is a "No Compile Test" suite. |
6 | // http://dev.chromium.org/developers/testing/no-compile-tests | ||||
7 | |||||
[email protected] | 2a7cac0 | 2013-09-26 19:20:18 | [diff] [blame] | 8 | #include "base/callback_list.h" |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 9 | |
dcheng | 093de9b | 2016-04-04 21:25:51 | [diff] [blame] | 10 | #include <memory> |
tzik | a6e26be | 2016-01-05 02:52:52 | [diff] [blame] | 11 | #include <utility> |
12 | |||||
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 13 | #include "base/bind.h" |
14 | #include "base/bind_helpers.h" | ||||
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 16 | |
17 | namespace base { | ||||
18 | |||||
19 | class Foo { | ||||
20 | public: | ||||
21 | Foo() {} | ||||
22 | ~Foo() {} | ||||
23 | }; | ||||
24 | |||||
25 | class FooListener { | ||||
26 | public: | ||||
27 | FooListener() {} | ||||
28 | |||||
dcheng | 093de9b | 2016-04-04 21:25:51 | [diff] [blame] | 29 | void GotAScopedFoo(std::unique_ptr<Foo> f) { foo_ = std::move(f); } |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 30 | |
dcheng | 093de9b | 2016-04-04 21:25:51 | [diff] [blame] | 31 | std::unique_ptr<Foo> foo_; |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 32 | |
33 | private: | ||||
34 | DISALLOW_COPY_AND_ASSIGN(FooListener); | ||||
35 | }; | ||||
36 | |||||
37 | |||||
wychen | e1a7b9b | 2017-01-04 13:21:55 | [diff] [blame] | 38 | #if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to (implicitly-)?deleted( copy)? constructor"] |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 39 | |
40 | // Callbacks run with a move-only typed parameter. | ||||
41 | // | ||||
[email protected] | 2a7cac0 | 2013-09-26 19:20:18 | [diff] [blame] | 42 | // CallbackList does not support move-only typed parameters. Notify() is |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 43 | // designed to take zero or more parameters, and run each registered callback |
44 | // with them. With move-only types, the parameter will be set to NULL after the | ||||
45 | // first callback has been run. | ||||
46 | void WontCompile() { | ||||
47 | FooListener f; | ||||
dcheng | 093de9b | 2016-04-04 21:25:51 | [diff] [blame] | 48 | CallbackList<void(std::unique_ptr<Foo>)> c1; |
49 | std::unique_ptr<CallbackList<void(std::unique_ptr<Foo>)>::Subscription> sub = | ||||
kylechar | b2695fc | 2019-04-24 14:51:20 | [diff] [blame] | 50 | c1.Add(BindRepeating(&FooListener::GotAScopedFoo, Unretained(&f))); |
dcheng | 093de9b | 2016-04-04 21:25:51 | [diff] [blame] | 51 | c1.Notify(std::unique_ptr<Foo>(new Foo())); |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 52 | } |
53 | |||||
54 | #endif | ||||
55 | |||||
56 | } // namespace base |