bind_post_task_unittest.nc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2020 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. // This is a "No Compile Test" suite.
  5. // http://dev.chromium.org/developers/testing/no-compile-tests
  6. #include "base/task/bind_post_task.h"
  7. #include "base/bind.h"
  8. #include "base/callback.h"
  9. #include "base/threading/sequenced_task_runner_handle.h"
  10. namespace base {
  11. int ReturnInt() {
  12. return 5;
  13. }
  14. #if defined(NCTEST_ONCE_NON_VOID_RETURN) // [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."]
  15. // OnceCallback with non-void return type.
  16. void WontCompile() {
  17. OnceCallback<int()> cb = BindOnce(&ReturnInt);
  18. auto post_cb = BindPostTask(SequencedTaskRunnerHandle::Get(), std::move(cb));
  19. std::move(post_cb).Run();
  20. }
  21. #elif defined(NCTEST_REPEATING_NON_VOID_RETURN) // [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."]
  22. // RepeatingCallback with non-void return type.
  23. void WontCompile() {
  24. RepeatingCallback<int()> cb = BindRepeating(&ReturnInt);
  25. auto post_cb = BindPostTask(SequencedTaskRunnerHandle::Get(), std::move(cb));
  26. std::move(post_cb).Run();
  27. }
  28. #endif
  29. } // namespace base