[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" |
| 13 | #include "base/memory/scoped_ptr.h" |
| 14 | |
| 15 | namespace base { |
| 16 | |
| 17 | class Foo { |
| 18 | public: |
| 19 | Foo() {} |
| 20 | ~Foo() {} |
| 21 | }; |
| 22 | |
| 23 | class FooListener { |
| 24 | public: |
| 25 | FooListener() {} |
| 26 | |
| 27 | void GotAScopedFoo(scoped_ptr<Foo> f) { foo_ = f.Pass(); } |
| 28 | |
| 29 | scoped_ptr<Foo> foo_; |
| 30 | |
| 31 | private: |
| 32 | DISALLOW_COPY_AND_ASSIGN(FooListener); |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | #if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"calling a private constructor of class"] |
| 37 | |
| 38 | // Callbacks run with a move-only typed parameter. |
| 39 | // |
[email protected] | 2a7cac0 | 2013-09-26 19:20:18 | [diff] [blame] | 40 | // CallbackList does not support move-only typed parameters. Notify() is |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 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 |
| 43 | // first callback has been run. |
| 44 | void WontCompile() { |
| 45 | FooListener f; |
[email protected] | 2a7cac0 | 2013-09-26 19:20:18 | [diff] [blame] | 46 | CallbackList<void(scoped_ptr<Foo>)> c1; |
| 47 | scoped_ptr<CallbackList<void(scoped_ptr<Foo>)>::Subscription> sub = |
[email protected] | 243576f | 2013-09-25 13:56:23 | [diff] [blame] | 48 | c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f))); |
| 49 | c1.Notify(scoped_ptr<Foo>(new Foo())); |
| 50 | } |
| 51 | |
| 52 | #endif |
| 53 | |
| 54 | } // namespace base |