1// RUN: %check_clang_tidy -std=c++20 %s modernize-loop-convert %t -- -- -I %S/Inputs/loop-convert
2
3namespace std {
4struct strong_ordering {
5 int n;
6 constexpr operator int() const { return n; }
7 static const strong_ordering equal, greater, less;
8};
9constexpr strong_ordering strong_ordering::equal = {.n: 0};
10constexpr strong_ordering strong_ordering::greater = {.n: 1};
11constexpr strong_ordering strong_ordering::less = {.n: -1};
12} // namespace std
13
14struct HasSpaceshipMem {
15 typedef int value_type;
16
17 struct iterator {
18 value_type &operator*();
19 const value_type &operator*() const;
20 iterator &operator++();
21 void insert(value_type);
22 value_type X;
23 constexpr auto operator<=>(const HasSpaceshipMem::iterator &) const = default;
24 };
25
26 iterator begin();
27 iterator end();
28};
29
30struct OpEqOnly {
31 typedef int value_type;
32 struct iterator {
33 value_type &operator*();
34 const value_type &operator*() const;
35 iterator &operator++();
36 bool operator==(const iterator &other) const;
37 void insert(value_type);
38 value_type X;
39 };
40 iterator begin();
41 iterator end();
42};
43
44void rewritten() {
45 OpEqOnly Oeo;
46 for (OpEqOnly::iterator It = Oeo.begin(), E = Oeo.end(); It != E; ++It) {
47 (void)*It;
48 }
49 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
50 // CHECK-FIXES: for (int & It : Oeo)
51 // CHECK-FIXES-NEXT: (void)It;
52
53 HasSpaceshipMem Hsm;
54 for (HasSpaceshipMem::iterator It = Hsm.begin(), E = Hsm.end(); It != E; ++It) {
55 (void)*It;
56 }
57 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
58 // CHECK-FIXES: for (int & It : Hsm)
59 // CHECK-FIXES-NEXT: (void)It;
60}
61

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-rewritten-binop.cpp