summaryrefslogtreecommitdiff
path: root/chromium/base/functional/function_ref_unittest.nc
blob: 927c778ed7bc703c3f3bdff93e611d84069981e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a "No Compile Test" suite.
// http://dev.chromium.org/developers/testing/no-compile-tests

#include "base/bind.h"
#include "base/callback.h"
#include "base/functional/function_ref.h"
#include "third_party/abseil-cpp/absl/functional/function_ref.h"

namespace base {

#if defined(NCTEST_NO_IMPLICIT_VOIDIFY)  // [r"note: candidate template ignored: requirement '[^']+' was not satisfied \[with Functor = \(lambda at [^)]+\)\]"]

void WontCompile() {
  auto returns_int = [] () { return 42; };
  FunctionRef<void()> ref(returns_int);
}

#elif defined(NCTEST_BIND_ONCE_TO_ABSL_FUNCTION_REF)  // [r"fatal error: static assertion failed due to requirement 'AlwaysFalse<void \(\)>': base::Bind{Once,Repeating} require strong ownership: non-owning function references may not bound as the functor due to potential lifetime issues\."]

void WontCompile() {
  [] (absl::FunctionRef<void()> ref) {
    BindOnce(ref).Run();
  }([] {});
}

#elif defined(NCTEST_BIND_REPEATING_TO_ABSL_FUNCTION_REF)  // [r"fatal error: static assertion failed due to requirement 'AlwaysFalse<void \(\)>': base::Bind{Once,Repeating} require strong ownership: non-owning function references may not bound as the functor due to potential lifetime issues\."]

void WontCompile() {
  [] (FunctionRef<void()> ref) {
    BindRepeating(ref).Run();
  }([] {});
}

#elif defined(NCTEST_BIND_ONCE_TO_BASE_FUNCTION_REF)  // [r"fatal error: static assertion failed due to requirement 'AlwaysFalse<void \(\)>': base::Bind{Once,Repeating} require strong ownership: non-owning function references may not bound as the functor due to potential lifetime issues\."]

void WontCompile() {
  [] (FunctionRef<void()> ref) {
    BindOnce(ref).Run();
  }([] {});
}

#elif defined(NCTEST_BIND_REPEATING_TO_BASE_FUNCTION_REF)  // [r"fatal error: static assertion failed due to requirement 'AlwaysFalse<void \(\)>': base::Bind{Once,Repeating} require strong ownership: non-owning function references may not bound as the functor due to potential lifetime issues\."]

void WontCompile() {
  [] (FunctionRef<void()> ref) {
    BindRepeating(ref).Run();
  }([] {});
}

#endif

}  // namespace base