1// Copyright 2020 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/task/bind_post_task.h" 9 10#include "base/task/sequenced_task_runner.h" 11#include "base/functional/bind.h" 12#include "base/functional/callback.h" 13 14namespace base { 15 16// In general, compilers only print diagnostics for errors once when initially 17// instantiating the template. Subsequent uses of the same template will not 18// print out any diagnostics. 19// 20// Using multiple functions that return different types ensures that each 21// BindPostTask() call creates a new instantiation. 22int ReturnsInt(); 23double ReturnsDouble(); 24 25void OnceCallbackWithNonVoidReturnType() { 26 { 27 OnceCallback<int()> cb = BindOnce(&ReturnsInt); 28 auto post_cb = BindPostTask(SequencedTaskRunner::GetCurrentDefault(), std::move(cb)); // expected-error@base/task/bind_post_task.h:* {{OnceCallback must have void return type in order to produce a closure for PostTask().}} 29 // expected-error@*:* {{no matching constructor for initialization}} 30 } 31 32 { 33 OnceCallback<double()> cb = BindOnce(&ReturnsDouble); 34 auto post_cb = BindPostTaskToCurrentDefault(std::move(cb)); // expected-error@base/task/bind_post_task.h:* {{OnceCallback must have void return type in order to produce a closure for PostTask().}} 35 // expected-error@*:* {{no matching constructor for initialization}} 36 } 37} 38 39void RepeatingCallbackWithNonVoidReturnType() { 40 { 41 RepeatingCallback<int()> cb = BindRepeating(&ReturnsInt); 42 auto post_cb = BindPostTask(SequencedTaskRunner::GetCurrentDefault(), std::move(cb)); // expected-error@base/task/bind_post_task.h:* {{RepeatingCallback must have void return type in order to produce a closure for PostTask().}} 43 // expected-error@*:* {{no matching constructor for initialization}} 44 } 45 46 { 47 RepeatingCallback<double()> cb = BindRepeating(&ReturnsDouble); 48 auto post_cb = BindPostTaskToCurrentDefault(std::move(cb)); // expected-error@base/task/bind_post_task.h:* {{RepeatingCallback must have void return type in order to produce a closure for PostTask().}} 49 // expected-error@*:* {{no matching constructor for initialization}} 50 } 51} 52 53} // namespace base 54