1 | // RUN: %check_clang_tidy -std=c++20 %s readability-container-size-empty %t -- -- -fno-delayed-template-parsing |
2 | |
3 | namespace std { |
4 | struct strong_ordering { |
5 | int n; |
6 | constexpr operator int() const { return n; } |
7 | static const strong_ordering equal, greater, less; |
8 | }; |
9 | constexpr strong_ordering strong_ordering::equal = {.n: 0}; |
10 | constexpr strong_ordering strong_ordering::greater = {.n: 1}; |
11 | constexpr strong_ordering strong_ordering::less = {.n: -1}; |
12 | } // namespace std |
13 | |
14 | template <typename T> |
15 | struct OpEqOnly { |
16 | OpEqOnly(); |
17 | bool operator==(const OpEqOnly<T> &other) const; |
18 | unsigned long size() const; |
19 | bool empty() const; |
20 | }; |
21 | |
22 | template <typename T> |
23 | struct HasSpaceshipMem { |
24 | HasSpaceshipMem(); |
25 | bool operator<=>(const HasSpaceshipMem<T> &other) const = default; |
26 | unsigned long size() const; |
27 | bool empty() const; |
28 | }; |
29 | |
30 | void returnsVoid() { |
31 | OpEqOnly<int> OEO; |
32 | HasSpaceshipMem<int> HSM; |
33 | |
34 | if (OEO != OpEqOnly<int>()) |
35 | ; |
36 | // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness |
37 | // CHECK-FIXES: {{^ }}if (!OEO.empty()){{$}} |
38 | // CHECK-MESSAGES: :19:8: note: method 'OpEqOnly'::empty() defined here |
39 | if (HSM != HasSpaceshipMem<int>()) |
40 | ; |
41 | // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness |
42 | // CHECK-FIXES: {{^ }}if (!HSM.empty()){{$}} |
43 | // CHECK-MESSAGES: :27:8: note: method 'HasSpaceshipMem'::empty() defined here |
44 | } |
45 | |