1// Copyright 2013 The Chromium Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// This is a "No Compile Test" suite. 6// http://dev.chromium.org/developers/testing/no-compile-tests 7 8#include "base/callback_list.h" 9 10#include <memory> 11#include <utility> 12 13#include "base/functional/bind.h" 14#include "base/functional/callback_helpers.h" 15 16namespace base { 17 18class Foo { 19 public: 20 Foo() {} 21 ~Foo() {} 22}; 23 24class FooListener { 25 public: 26 FooListener() = default; 27 FooListener(const FooListener&) = delete; 28 FooListener& operator=(const FooListener&) = delete; 29 30 void GotAScopedFoo(std::unique_ptr<Foo> f) { foo_ = std::move(f); } 31 32 std::unique_ptr<Foo> foo_; 33}; 34 35 36#if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to (implicitly-)?deleted( copy)? constructor"] 37 38// Callbacks run with a move-only typed parameter. 39// 40// CallbackList does not support move-only typed parameters. Notify() is 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. 44void WontCompile() { 45 FooListener f; 46 RepeatingCallbackList<void(std::unique_ptr<Foo>)> c1; 47 CallbackListSubscription sub = 48 c1.Add(BindRepeating(&FooListener::GotAScopedFoo, Unretained(&f))); 49 c1.Notify(std::unique_ptr<Foo>(new Foo())); 50} 51 52#endif 53 54} // namespace base 55