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 16int ReturnInt() { 17 return 5; 18} 19 20#if defined(NCTEST_ONCE_NON_VOID_RETURN_BIND_POST_TASK) // [r"fatal error: static assertion failed due to requirement 'std::is_same<int, void>::value': OnceCallback must have void return type in order to produce a closure for PostTask\(\). Use base::IgnoreResult\(\) to drop the return value if desired."] 21// OnceCallback with non-void return type. 22void WontCompile() { 23 OnceCallback<int()> cb = BindOnce(&ReturnInt); 24 auto post_cb = BindPostTask(SequencedTaskRunner::GetCurrentDefault(), std::move(cb)); 25 std::move(post_cb).Run(); 26} 27 28#elif defined(NCTEST_REPEATING_NON_VOID_RETURN_BIND_POST_TASK) // [r"fatal error: static assertion failed due to requirement 'std::is_same<int, void>::value': RepeatingCallback must have void return type in order to produce a closure for PostTask\(\). Use base::IgnoreResult\(\) to drop the return value if desired."] 29// RepeatingCallback with non-void return type. 30void WontCompile() { 31 RepeatingCallback<int()> cb = BindRepeating(&ReturnInt); 32 auto post_cb = BindPostTask(SequencedTaskRunner::GetCurrentDefault(), std::move(cb)); 33 std::move(post_cb).Run(); 34} 35 36#elif defined(NCTEST_ONCE_NON_VOID_RETURN_BIND_POST_TASK_TO_CURRENT_DEFAULT) // [r"fatal error: static assertion failed due to requirement 'std::is_same<int, void>::value': OnceCallback must have void return type in order to produce a closure for PostTask\(\). Use base::IgnoreResult\(\) to drop the return value if desired."] 37// OnceCallback with non-void return type. 38void WontCompile() { 39 OnceCallback<int()> cb = BindOnce(&ReturnInt); 40 auto post_cb = BindPostTaskToCurrentDefault(std::move(cb)); 41 std::move(post_cb).Run(); 42} 43 44#elif defined(NCTEST_REPEATING_NON_VOID_RETURN_BIND_POST_TASK_TO_CURRENT_DEFAULT) // [r"fatal error: static assertion failed due to requirement 'std::is_same<int, void>::value': RepeatingCallback must have void return type in order to produce a closure for PostTask\(\). Use base::IgnoreResult\(\) to drop the return value if desired."] 45// RepeatingCallback with non-void return type. 46void WontCompile() { 47 RepeatingCallback<int()> cb = BindRepeating(&ReturnInt); 48 auto post_cb = BindPostTaskToCurrentDefault(std::move(cb)); 49 std::move(post_cb).Run(); 50} 51 52#endif 53 54} // namespace base 55