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 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/bind.h" 14#include "base/bind_helpers.h" 15#include "base/macros.h" 16 17namespace base { 18 19class Foo { 20 public: 21 Foo() {} 22 ~Foo() {} 23}; 24 25class FooListener { 26 public: 27 FooListener() {} 28 29 void GotAScopedFoo(std::unique_ptr<Foo> f) { foo_ = std::move(f); } 30 31 std::unique_ptr<Foo> foo_; 32 33 private: 34 DISALLOW_COPY_AND_ASSIGN(FooListener); 35}; 36 37 38#if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to (implicitly-)?deleted( copy)? constructor"] 39 40// Callbacks run with a move-only typed parameter. 41// 42// CallbackList does not support move-only typed parameters. Notify() is 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. 46void WontCompile() { 47 FooListener f; 48 CallbackList<void(std::unique_ptr<Foo>)> c1; 49 std::unique_ptr<CallbackList<void(std::unique_ptr<Foo>)>::Subscription> sub = 50 c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f))); 51 c1.Notify(std::unique_ptr<Foo>(new Foo())); 52} 53 54#endif 55 56} // namespace base 57