modernize-avoid-bind-permissive-parameter-list.cpp
1.63 KB
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
57
58
// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-avoid-bind %t -- \
// RUN: -config="{CheckOptions: [ \
// RUN: {key: modernize-avoid-bind.PermissiveParameterList, value: 1}]}" --
namespace std {
inline namespace impl {
template <class Fp, class... Arguments>
class bind_rt {};
template <class Fp, class... Arguments>
bind_rt<Fp, Arguments...> bind(Fp &&, Arguments &&...);
} // namespace impl
template <typename T>
T ref(T &t);
} // namespace std
int add(int x, int y) { return x + y; }
// Let's fake a minimal std::function-like facility.
namespace std {
template <typename _Tp>
_Tp declval();
template <typename _Functor, typename... _ArgTypes>
struct __res {
template <typename... _Args>
static decltype(declval<_Functor>()(_Args()...)) _S_test(int);
template <typename...>
static void _S_test(...);
using type = decltype(_S_test<_ArgTypes...>(0));
};
template <typename>
struct function;
template <typename... _ArgTypes>
struct function<void(_ArgTypes...)> {
template <typename _Functor,
typename = typename __res<_Functor, _ArgTypes...>::type>
function(_Functor) {}
};
} // namespace std
struct placeholder {};
placeholder _1;
void testLiteralParameters() {
auto AAA = std::bind(add, 2, 2);
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind [modernize-avoid-bind]
// CHECK-FIXES: auto AAA = [](auto && ...) { return add(2, 2); };
auto BBB = std::bind(add, _1, 2);
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind [modernize-avoid-bind]
// CHECK-FIXES: auto BBB = [](auto && PH1, auto && ...) { return add(std::forward<decltype(PH1)>(PH1), 2); };
}