[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 | |
tzik | a6e26be | 2016-01-05 02:52:52 | [diff] [blame] | 10 | #include <utility> |
11 | |||||
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 12 | #include "base/bind.h" |
13 | #include "base/bind_helpers.h" | ||||
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 15 | #include "base/memory/scoped_ptr.h" |
16 | |||||
17 | namespace base { | ||||
18 | |||||
19 | class Foo { | ||||
20 | public: | ||||
21 | Foo() {} | ||||
22 | ~Foo() {} | ||||
23 | }; | ||||
24 | |||||
25 | class FooListener { | ||||
26 | public: | ||||
27 | FooListener() {} | ||||
28 | |||||
tzik | a6e26be | 2016-01-05 02:52:52 | [diff] [blame] | 29 | void GotAScopedFoo(scoped_ptr<Foo> f) { foo_ = std::move(f); } |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 30 | |
31 | scoped_ptr<Foo> foo_; | ||||
32 | |||||
33 | private: | ||||
34 | DISALLOW_COPY_AND_ASSIGN(FooListener); | ||||
35 | }; | ||||
36 | |||||
37 | |||||
tzik | 096369a | 2015-12-11 06:39:06 | [diff] [blame] | 38 | #if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to deleted 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; | ||||
[email protected] | 2a7cac0 | 2013-09-26 19:20:18 | [diff] [blame] | 48 | CallbackList<void(scoped_ptr<Foo>)> c1; |
49 | scoped_ptr<CallbackList<void(scoped_ptr<Foo>)>::Subscription> sub = | ||||
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 50 | c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f))); |
51 | c1.Notify(scoped_ptr<Foo>(new Foo())); | ||||
52 | } | ||||
53 | |||||
54 | #endif | ||||
55 | |||||
56 | } // namespace base |