1// Copyright 2022 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/functional/bind.h" 9#include "base/functional/callback.h" 10#include "base/functional/function_ref.h" 11#include "third_party/abseil-cpp/absl/functional/function_ref.h" 12 13namespace base { 14 15#if defined(NCTEST_NO_IMPLICIT_VOIDIFY) // [r"note: candidate template ignored: requirement '[^']+' was not satisfied \[with Functor = \(lambda at [^)]+\)\]"] 16 17void WontCompile() { 18 auto returns_int = [] () { return 42; }; 19 FunctionRef<void()> ref(returns_int); 20} 21 22#elif defined(NCTEST_BIND_ONCE_TO_ABSL_FUNCTION_REF) // [r"base::Bind{Once,Repeating} require strong ownership: non-owning function references may not be bound as the functor due to potential lifetime issues\."] 23 24void WontCompile() { 25 [] (absl::FunctionRef<void()> ref) { 26 BindOnce(ref).Run(); 27 }([] {}); 28} 29 30#elif defined(NCTEST_BIND_REPEATING_TO_ABSL_FUNCTION_REF) // [r"base::Bind{Once,Repeating} require strong ownership: non-owning function references may not be bound as the functor due to potential lifetime issues\."] 31 32void WontCompile() { 33 [] (FunctionRef<void()> ref) { 34 BindRepeating(ref).Run(); 35 }([] {}); 36} 37 38#elif defined(NCTEST_BIND_ONCE_TO_BASE_FUNCTION_REF) // [r"base::Bind{Once,Repeating} require strong ownership: non-owning function references may not be bound as the functor due to potential lifetime issues\."] 39 40void WontCompile() { 41 [] (FunctionRef<void()> ref) { 42 BindOnce(ref).Run(); 43 }([] {}); 44} 45 46#elif defined(NCTEST_BIND_REPEATING_TO_BASE_FUNCTION_REF) // [r"base::Bind{Once,Repeating} require strong ownership: non-owning function references may not be bound as the functor due to potential lifetime issues\."] 47 48void WontCompile() { 49 [] (FunctionRef<void()> ref) { 50 BindRepeating(ref).Run(); 51 }([] {}); 52} 53 54#endif 55 56} // namespace base 57