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 OnceCallbackWithNonVoidReturnType1() { 26 { 27 OnceCallback<int()> cb = BindOnce(&ReturnsInt); 28 auto post_cb = BindPostTask(SequencedTaskRunner::GetCurrentDefault(), std::move(cb)); // expected-error@base/task/bind_post_task_nocompile.nc:* {{no matching function for call to 'BindPostTask'}} 29 // expected-note@base/task/bind_post_task.h:* {{because 'std::is_void_v<int>' evaluated to false}} 30 31 } 32 33 { 34 OnceCallback<double()> cb = BindOnce(&ReturnsDouble); 35 auto post_cb = BindPostTaskToCurrentDefault(std::move(cb)); // expected-error@base/task/bind_post_task_nocompile.nc:* {{no matching function for call to 'BindPostTaskToCurrentDefault'}} 36 } // expected-note@base/task/bind_post_task.h:* {{because 'std::is_void_v<double>' evaluated to false}} 37 38} 39 40void RepeatingCallbackWithNonVoidReturnType() { 41 { 42 RepeatingCallback<int()> cb = BindRepeating(&ReturnsInt); 43 auto post_cb = BindPostTask(SequencedTaskRunner::GetCurrentDefault(), std::move(cb)); // expected-error@base/task/bind_post_task_nocompile.nc:* {{no matching function for call to 'BindPostTask'}} 44 // expected-note@base/task/bind_post_task.h:* {{because 'std::is_void_v<int>' evaluated to false}} 45 } 46 47 { 48 RepeatingCallback<double()> cb = BindRepeating(&ReturnsDouble); 49 auto post_cb = BindPostTaskToCurrentDefault(std::move(cb)); // expected-error@base/task/bind_post_task_nocompile.nc:* {{no matching function for call to 'BindPostTaskToCurrentDefault'}} 50 // expected-note@base/task/bind_post_task.h:* {{because 'std::is_void_v<double>' evaluated to false}} 51 52 } 53} 54 55} // namespace base 56