1 // RUN: %check_clang_tidy -std=c++14-or-later %s modernize-avoid-bind %t -- \
2 // RUN: -config="{CheckOptions: [ \
3 // RUN: {key: modernize-avoid-bind.PermissiveParameterList, value: true}]}" --
4
5 namespace std {
6 inline namespace impl {
7 template <class Fp, class... Arguments>
8 class bind_rt {};
9
10 template <class Fp, class... Arguments>
11 bind_rt<Fp, Arguments...> bind(Fp &&, Arguments &&...);
12 } // namespace impl
13
14 template <typename T>
15 T ref(T &t);
16 } // namespace std
17
add(int x,int y)18 int add(int x, int y) { return x + y; }
19
20 // Let's fake a minimal std::function-like facility.
21 namespace std {
22 template <typename _Tp>
23 _Tp declval();
24
25 template <typename _Functor, typename... _ArgTypes>
26 struct __res {
27 template <typename... _Args>
28 static decltype(declval<_Functor>()(_Args()...)) _S_test(int);
29
30 template <typename...>
31 static void _S_test(...);
32
33 using type = decltype(_S_test<_ArgTypes...>(0));
34 };
35
36 template <typename>
37 struct function;
38
39 template <typename... _ArgTypes>
40 struct function<void(_ArgTypes...)> {
41 template <typename _Functor,
42 typename = typename __res<_Functor, _ArgTypes...>::type>
functionstd::function43 function(_Functor) {}
44 };
45 } // namespace std
46
47 struct placeholder {};
48 placeholder _1;
49
testLiteralParameters()50 void testLiteralParameters() {
51 auto AAA = std::bind(add, 2, 2);
52 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind [modernize-avoid-bind]
53 // CHECK-FIXES: auto AAA = [](auto && ...) { return add(2, 2); };
54
55 auto BBB = std::bind(add, _1, 2);
56 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind [modernize-avoid-bind]
57 // CHECK-FIXES: auto BBB = [](auto && PH1, auto && ...) { return add(std::forward<decltype(PH1)>(PH1), 2); };
58 }
59