blob: c6af89a3d29a1cbbcce88d7c4a2682a8e67880fd [file] [log] [blame]
[email protected]243576f2013-09-25 13:56:231// 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
scheib0411d8f72015-10-19 19:29:555// This is a "No Compile Test" suite.
6// http://dev.chromium.org/developers/testing/no-compile-tests
7
[email protected]2a7cac02013-09-26 19:20:188#include "base/callback_list.h"
[email protected]243576f2013-09-25 13:56:239
dcheng093de9b2016-04-04 21:25:5110#include <memory>
tzika6e26be2016-01-05 02:52:5211#include <utility>
12
[email protected]243576f2013-09-25 13:56:2313#include "base/bind.h"
14#include "base/bind_helpers.h"
avi9b6f42932015-12-26 22:15:1415#include "base/macros.h"
[email protected]243576f2013-09-25 13:56:2316
17namespace base {
18
19class Foo {
20 public:
21 Foo() {}
22 ~Foo() {}
23};
24
25class FooListener {
26 public:
27 FooListener() {}
28
dcheng093de9b2016-04-04 21:25:5129 void GotAScopedFoo(std::unique_ptr<Foo> f) { foo_ = std::move(f); }
[email protected]243576f2013-09-25 13:56:2330
dcheng093de9b2016-04-04 21:25:5131 std::unique_ptr<Foo> foo_;
[email protected]243576f2013-09-25 13:56:2332
33 private:
34 DISALLOW_COPY_AND_ASSIGN(FooListener);
35};
36
37
wychene1a7b9b2017-01-04 13:21:5538#if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to (implicitly-)?deleted( copy)? constructor"]
[email protected]243576f2013-09-25 13:56:2339
40// Callbacks run with a move-only typed parameter.
41//
[email protected]2a7cac02013-09-26 19:20:1842// CallbackList does not support move-only typed parameters. Notify() is
[email protected]243576f2013-09-25 13:56:2343// 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.
46void WontCompile() {
47 FooListener f;
dcheng093de9b2016-04-04 21:25:5148 CallbackList<void(std::unique_ptr<Foo>)> c1;
49 std::unique_ptr<CallbackList<void(std::unique_ptr<Foo>)>::Subscription> sub =
kylecharb2695fc2019-04-24 14:51:2050 c1.Add(BindRepeating(&FooListener::GotAScopedFoo, Unretained(&f)));
dcheng093de9b2016-04-04 21:25:5151 c1.Notify(std::unique_ptr<Foo>(new Foo()));
[email protected]243576f2013-09-25 13:56:2352}
53
54#endif
55
56} // namespace base