1// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-transparent-functors %t
2
3namespace std {
4template<class T>
5struct remove_reference;
6
7template <class T>
8constexpr T &&forward(typename std::remove_reference<T>::type &t);
9
10template <class T>
11constexpr T &&forward(typename std::remove_reference<T>::type &&t);
12
13template <typename T = void>
14struct plus {
15 constexpr T operator()(const T &Lhs, const T &Rhs) const;
16};
17
18template <>
19struct plus<void> {
20 template <typename T, typename U>
21 constexpr auto operator()(T &&Lhs, U &&Rhs) const ->
22 decltype(forward<T>(Lhs) + forward<U>(Rhs));
23};
24
25template <typename T = void>
26struct less {
27 constexpr bool operator()(const T &Lhs, const T &Rhs) const;
28};
29
30template <>
31struct less<void> {
32 template <typename T, typename U>
33 constexpr bool operator()(T &&Lhs, U &&Rhs) const;
34};
35
36template <typename T = void>
37struct logical_not {
38 constexpr bool operator()(const T &Arg) const;
39};
40
41template <>
42struct logical_not<void> {
43 template <typename T>
44 constexpr bool operator()(T &&Arg) const;
45};
46
47template <typename T>
48class allocator;
49
50template <
51 class Key,
52 class Compare = std::less<>,
53 class Allocator = std::allocator<Key>>
54class set {};
55
56template <
57 class Key,
58 class Compare = std::less<Key>,
59 class Allocator = std::allocator<Key>>
60class set2 {};
61
62template <class InputIt, class UnaryPredicate>
63InputIt find_if(InputIt first, InputIt last,
64 UnaryPredicate p);
65
66template <class RandomIt, class Compare>
67void sort(RandomIt first, RandomIt last, Compare comp);
68
69class iterator {};
70class string {};
71}
72
73int main() {
74 using std::set;
75 using std::less;
76 std::set<int, std::less<int>> s;
77 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: prefer transparent functors 'less<>' [modernize-use-transparent-functors]
78 // CHECK-FIXES: {{^}} std::set<int, std::less<>> s;{{$}}
79 set<int, std::less<int>> s2;
80 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: prefer transparent functors
81 // CHECK-FIXES: {{^}} set<int, std::less<>> s2;{{$}}
82 set<int, less<int>> s3;
83 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: prefer transparent functors
84 // CHECK-FIXES: {{^}} set<int, less<>> s3;{{$}}
85 std::set<int, std::less<>> s4;
86 std::set<char *, std::less<std::string>> s5;
87 std::set<set<int, less<int>>, std::less<>> s6;
88 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: prefer transparent functors
89 // CHECK-FIXES: {{^}} std::set<set<int, less<>>, std::less<>> s6;{{$}}
90 std::iterator begin, end;
91 sort(first: begin, last: end, comp: std::less<int>());
92 // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: prefer transparent functors
93 std::sort(first: begin, last: end, comp: std::less<>());
94 find_if(first: begin, last: end, p: std::logical_not<bool>());
95 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors
96 std::find_if(first: begin, last: end, p: std::logical_not<>());
97 using my_set = std::set<int, std::less<int>>;
98 // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: prefer transparent functors
99 // CHECK-FIXES: {{^}} using my_set = std::set<int, std::less<>>;{{$}}
100 using my_set2 = std::set<char*, std::less<std::string>>;
101 using my_less = std::less<std::string>;
102 find_if(first: begin, last: end, p: my_less());
103 // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors
104 std::set2<int> control;
105}
106
107struct ImplicitTypeLoc : std::set2<std::less<int>> {
108 // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: prefer transparent functors
109 ImplicitTypeLoc() {}
110};
111

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/use-transparent-functors.cpp