1 // RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-transparent-functors %t
2 
3 namespace std {
4 template<class T>
5 struct remove_reference;
6 
7 template <class T>
8 constexpr T &&forward(typename std::remove_reference<T>::type &t);
9 
10 template <class T>
11 constexpr T &&forward(typename std::remove_reference<T>::type &&t);
12 
13 template <typename T = void>
14 struct plus {
15   constexpr T operator()(const T &Lhs, const T &Rhs) const;
16 };
17 
18 template <>
19 struct 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 
25 template <typename T = void>
26 struct less {
27   constexpr bool operator()(const T &Lhs, const T &Rhs) const;
28 };
29 
30 template <>
31 struct less<void> {
32   template <typename T, typename U>
33   constexpr bool operator()(T &&Lhs, U &&Rhs) const;
34 };
35 
36 template <typename T = void>
37 struct logical_not {
38   constexpr bool operator()(const T &Arg) const;
39 };
40 
41 template <>
42 struct logical_not<void> {
43   template <typename T>
44   constexpr bool operator()(T &&Arg) const;
45 };
46 
47 template <typename T>
48 class allocator;
49 
50 template <
51     class Key,
52     class Compare = std::less<>,
53     class Allocator = std::allocator<Key>>
54 class set {};
55 
56 template <
57     class Key,
58     class Compare = std::less<Key>,
59     class Allocator = std::allocator<Key>>
60 class set2 {};
61 
62 template <class InputIt, class UnaryPredicate>
63 InputIt find_if(InputIt first, InputIt last,
64                 UnaryPredicate p);
65 
66 template <class RandomIt, class Compare>
67 void sort(RandomIt first, RandomIt last, Compare comp);
68 
69 class iterator {};
70 class string {};
71 }
72 
main()73 int 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(begin, end, std::less<int>());
92   // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: prefer transparent functors
93   std::sort(begin, end, std::less<>());
94   find_if(begin, end, std::logical_not<bool>());
95   // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors
96   std::find_if(begin, end, 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(begin, end, my_less());
103   // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer transparent functors
104   std::set2<int> control;
105 }
106 
107 struct ImplicitTypeLoc : std::set2<std::less<int>> {
108   // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: prefer transparent functors
ImplicitTypeLocImplicitTypeLoc109   ImplicitTypeLoc() {}
110 };
111