xref: /aosp_15_r20/external/cronet/base/functional/function_ref_nocompile.nc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
12namespace base {
13
14void CannotBindFunctionRefs() {
15  // `Bind{Once,Repeating}` do not accept `FunctionRef` args due to potential
16  // lifetime concerns.
17  [](FunctionRef<void()> ref) { BindOnce(ref); }([] {});             // expected-error@*:* {{Functor may not be a FunctionRef, since that is a non-owning reference that may go out of scope before the callback executes.}}
18  [](FunctionRef<void()> ref) { BindRepeating(ref); }([] {});        // expected-error@*:* {{Functor may not be a FunctionRef, since that is a non-owning reference that may go out of scope before the callback executes.}}
19}
20
21}  // namespace base
22