[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 | |
10 | #include "base/basictypes.h" | ||||
11 | #include "base/bind.h" | ||||
12 | #include "base/bind_helpers.h" | ||||
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame^] | 13 | #include "base/macros.h" |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
15 | |||||
16 | namespace base { | ||||
17 | |||||
18 | class Foo { | ||||
19 | public: | ||||
20 | Foo() {} | ||||
21 | ~Foo() {} | ||||
22 | }; | ||||
23 | |||||
24 | class FooListener { | ||||
25 | public: | ||||
26 | FooListener() {} | ||||
27 | |||||
28 | void GotAScopedFoo(scoped_ptr<Foo> f) { foo_ = f.Pass(); } | ||||
29 | |||||
30 | scoped_ptr<Foo> foo_; | ||||
31 | |||||
32 | private: | ||||
33 | DISALLOW_COPY_AND_ASSIGN(FooListener); | ||||
34 | }; | ||||
35 | |||||
36 | |||||
tzik | 096369a | 2015-12-11 06:39:06 | [diff] [blame] | 37 | #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] | 38 | |
39 | // Callbacks run with a move-only typed parameter. | ||||
40 | // | ||||
[email protected] | 2a7cac0 | 2013-09-26 19:20:18 | [diff] [blame] | 41 | // CallbackList does not support move-only typed parameters. Notify() is |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 42 | // designed to take zero or more parameters, and run each registered callback |
43 | // with them. With move-only types, the parameter will be set to NULL after the | ||||
44 | // first callback has been run. | ||||
45 | void WontCompile() { | ||||
46 | FooListener f; | ||||
[email protected] | 2a7cac0 | 2013-09-26 19:20:18 | [diff] [blame] | 47 | CallbackList<void(scoped_ptr<Foo>)> c1; |
48 | scoped_ptr<CallbackList<void(scoped_ptr<Foo>)>::Subscription> sub = | ||||
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 49 | c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f))); |
50 | c1.Notify(scoped_ptr<Foo>(new Foo())); | ||||
51 | } | ||||
52 | |||||
53 | #endif | ||||
54 | |||||
55 | } // namespace base |