1// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-avoid-bind %t -- \
2// RUN: -config="{CheckOptions: { \
3// RUN: modernize-avoid-bind.PermissiveParameterList: true}}" --
4
5namespace std {
6inline namespace impl {
7template <class Fp, class... Arguments>
8class bind_rt {};
9
10template <class Fp, class... Arguments>
11bind_rt<Fp, Arguments...> bind(Fp &&, Arguments &&...);
12} // namespace impl
13
14template <typename T>
15T ref(T &t);
16} // namespace std
17
18int add(int x, int y) { return x + y; }
19
20// Let's fake a minimal std::function-like facility.
21namespace std {
22template <typename _Tp>
23_Tp declval();
24
25template <typename _Functor, typename... _ArgTypes>
26struct __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
36template <typename>
37struct function;
38
39template <typename... _ArgTypes>
40struct function<void(_ArgTypes...)> {
41 template <typename _Functor,
42 typename = typename __res<_Functor, _ArgTypes...>::type>
43 function(_Functor) {}
44};
45} // namespace std
46
47struct placeholder {};
48placeholder _1;
49
50void 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

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind-permissive-parameter-list.cpp