1// RUN: %check_clang_tidy %s readability-operators-representation %t -- -config="{CheckOptions: {\
2// RUN: readability-operators-representation.BinaryOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^=', \
3// RUN: readability-operators-representation.OverloadedOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^='}}" --
4
5void testAllTokensToAlternative(int a, int b) {
6 int value = 0;
7
8 value = a or b;
9 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'or' is an alternative token spelling, consider using a traditional token '||' for consistency [readability-operators-representation]
10 // CHECK-FIXES: {{^ }}value = a || b;{{$}}
11
12 value = a and b;
13 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'and' is an alternative token spelling, consider using a traditional token '&&' for consistency [readability-operators-representation]
14 // CHECK-FIXES: {{^ }}value = a && b;{{$}}
15
16 value = a bitor b;
17 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitor' is an alternative token spelling, consider using a traditional token '|' for consistency [readability-operators-representation]
18 // CHECK-FIXES: {{^ }}value = a | b;{{$}}
19
20 value = a bitand b;
21 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitand' is an alternative token spelling, consider using a traditional token '&' for consistency [readability-operators-representation]
22 // CHECK-FIXES: {{^ }}value = a & b;{{$}}
23
24 value = not a;
25 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'not' is an alternative token spelling, consider using a traditional token '!' for consistency [readability-operators-representation]
26 // CHECK-FIXES: {{^ }}value = ! a;{{$}}
27
28 value = a xor b;
29 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'xor' is an alternative token spelling, consider using a traditional token '^' for consistency [readability-operators-representation]
30 // CHECK-FIXES: {{^ }}value = a ^ b;{{$}}
31
32 value = compl b;
33 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'compl' is an alternative token spelling, consider using a traditional token '~' for consistency [readability-operators-representation]
34 // CHECK-FIXES: {{^ }}value = ~ b;{{$}}
35
36 value and_eq b;
37 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'and_eq' is an alternative token spelling, consider using a traditional token '&=' for consistency [readability-operators-representation]
38 // CHECK-FIXES: {{^ }}value &= b;{{$}}
39
40 value or_eq b;
41 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'or_eq' is an alternative token spelling, consider using a traditional token '|=' for consistency [readability-operators-representation]
42 // CHECK-FIXES: {{^ }}value |= b;{{$}}
43
44 value = a not_eq b;
45 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'not_eq' is an alternative token spelling, consider using a traditional token '!=' for consistency [readability-operators-representation]
46 // CHECK-FIXES: {{^ }}value = a != b;{{$}}
47
48 value xor_eq a;
49 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'xor_eq' is an alternative token spelling, consider using a traditional token '^=' for consistency [readability-operators-representation]
50 // CHECK-FIXES: {{^ }}value ^= a;{{$}}
51}
52
53struct Class {
54 bool operator!() const;
55 Class operator~() const;
56 bool operator&&(const Class&) const;
57 Class operator&(const Class&) const;
58 bool operator||(const Class&) const;
59 Class operator|(const Class&) const;
60 Class operator^(const Class&) const;
61 Class& operator&=(const Class&) const;
62 Class& operator|=(const Class&) const;
63 Class& operator^=(const Class&) const;
64 bool operator!=(const Class&) const;
65};
66
67void testAllTokensToAlternative(Class a, Class b) {
68 int value = 0;
69 Class clval;
70
71 value = a or b;
72 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'or' is an alternative token spelling, consider using a traditional token '||' for consistency [readability-operators-representation]
73 // CHECK-FIXES: {{^ }}value = a || b;{{$}}
74
75 value = a and b;
76 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'and' is an alternative token spelling, consider using a traditional token '&&' for consistency [readability-operators-representation]
77 // CHECK-FIXES: {{^ }}value = a && b;{{$}}
78
79 clval = a bitor b;
80 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitor' is an alternative token spelling, consider using a traditional token '|' for consistency [readability-operators-representation]
81 // CHECK-FIXES: {{^ }}clval = a | b;{{$}}
82
83 clval = a bitand b;
84 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitand' is an alternative token spelling, consider using a traditional token '&' for consistency [readability-operators-representation]
85 // CHECK-FIXES: {{^ }}clval = a & b;{{$}}
86
87 value = not a;
88 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'not' is an alternative token spelling, consider using a traditional token '!' for consistency [readability-operators-representation]
89 // CHECK-FIXES: {{^ }}value = ! a;{{$}}
90
91 clval = a xor b;
92 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'xor' is an alternative token spelling, consider using a traditional token '^' for consistency [readability-operators-representation]
93 // CHECK-FIXES: {{^ }}clval = a ^ b;{{$}}
94
95 clval = compl b;
96 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'compl' is an alternative token spelling, consider using a traditional token '~' for consistency [readability-operators-representation]
97 // CHECK-FIXES: {{^ }}clval = ~ b;{{$}}
98
99 clval and_eq b;
100 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'and_eq' is an alternative token spelling, consider using a traditional token '&=' for consistency [readability-operators-representation]
101 // CHECK-FIXES: {{^ }}clval &= b;{{$}}
102
103 clval or_eq b;
104 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'or_eq' is an alternative token spelling, consider using a traditional token '|=' for consistency [readability-operators-representation]
105 // CHECK-FIXES: {{^ }}clval |= b;{{$}}
106
107 value = a not_eq b;
108 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'not_eq' is an alternative token spelling, consider using a traditional token '!=' for consistency [readability-operators-representation]
109 // CHECK-FIXES: {{^ }}value = a != b;{{$}}
110
111 clval xor_eq a;
112 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'xor_eq' is an alternative token spelling, consider using a traditional token '^=' for consistency [readability-operators-representation]
113 // CHECK-FIXES: {{^ }}clval ^= a;{{$}}
114}
115
116struct ClassO {};
117
118ClassO& operator&=(ClassO&, const ClassO&);
119ClassO& operator|=(ClassO&, const ClassO&);
120ClassO& operator^=(ClassO&, const ClassO&);
121bool operator!=(const ClassO&, const ClassO&);
122bool operator&&(const ClassO&, const ClassO&);
123bool operator||(const ClassO&, const ClassO&);
124bool operator!(const ClassO&);
125ClassO operator&(const ClassO&, const ClassO&);
126ClassO operator|(const ClassO&, const ClassO&);
127ClassO operator^(const ClassO&, const ClassO&);
128ClassO operator~(const ClassO&);
129
130void testAllTokensToAlternative(ClassO a, ClassO b) {
131 int value = 0;
132 ClassO clval;
133
134 value = a or b;
135 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'or' is an alternative token spelling, consider using a traditional token '||' for consistency [readability-operators-representation]
136 // CHECK-FIXES: {{^ }}value = a || b;{{$}}
137
138 value = a and b;
139 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'and' is an alternative token spelling, consider using a traditional token '&&' for consistency [readability-operators-representation]
140 // CHECK-FIXES: {{^ }}value = a && b;{{$}}
141
142 clval = a bitor b;
143 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitor' is an alternative token spelling, consider using a traditional token '|' for consistency [readability-operators-representation]
144 // CHECK-FIXES: {{^ }}clval = a | b;{{$}}
145
146 clval = a bitand b;
147 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitand' is an alternative token spelling, consider using a traditional token '&' for consistency [readability-operators-representation]
148 // CHECK-FIXES: {{^ }}clval = a & b;{{$}}
149
150 value = not a;
151 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'not' is an alternative token spelling, consider using a traditional token '!' for consistency [readability-operators-representation]
152 // CHECK-FIXES: {{^ }}value = ! a;{{$}}
153
154 clval = a xor b;
155 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'xor' is an alternative token spelling, consider using a traditional token '^' for consistency [readability-operators-representation]
156 // CHECK-FIXES: {{^ }}clval = a ^ b;{{$}}
157
158 clval = compl b;
159 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'compl' is an alternative token spelling, consider using a traditional token '~' for consistency [readability-operators-representation]
160 // CHECK-FIXES: {{^ }}clval = ~ b;{{$}}
161
162 clval and_eq b;
163 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'and_eq' is an alternative token spelling, consider using a traditional token '&=' for consistency [readability-operators-representation]
164 // CHECK-FIXES: {{^ }}clval &= b;{{$}}
165
166 clval or_eq b;
167 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'or_eq' is an alternative token spelling, consider using a traditional token '|=' for consistency [readability-operators-representation]
168 // CHECK-FIXES: {{^ }}clval |= b;{{$}}
169
170 value = a not_eq b;
171 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'not_eq' is an alternative token spelling, consider using a traditional token '!=' for consistency [readability-operators-representation]
172 // CHECK-FIXES: {{^ }}value = a != b;{{$}}
173
174 clval xor_eq a;
175 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'xor_eq' is an alternative token spelling, consider using a traditional token '^=' for consistency [readability-operators-representation]
176 // CHECK-FIXES: {{^ }}clval ^= a;{{$}}
177}
178

source code of clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp