1 | // RUN: clang-tidy %s -checks='-*,hicpp-signed-bitwise' -- -std=c++11 |
---|---|
2 | // FIXME: Make the test work in all language modes. |
3 | |
4 | #include "signed-bitwise-standard-types.h" |
5 | |
6 | void pure_bitmask_types() { |
7 | // std::locale::category |
8 | int SResult = 0; |
9 | std::locale::category C = std::locale::category::ctype; |
10 | |
11 | SResult = std::locale::category::none | std::locale::category::collate; |
12 | SResult|= std::locale::category::collate; |
13 | SResult = std::locale::category::ctype & std::locale::category::monetary; |
14 | SResult&= std::locale::category::monetary; |
15 | SResult = std::locale::category::numeric ^ std::locale::category::time; |
16 | SResult^= std::locale::category::time; |
17 | SResult = std::locale::category::messages | std::locale::category::all; |
18 | |
19 | SResult = std::locale::category::all & C; |
20 | SResult&= std::locale::category::all; |
21 | SResult = std::locale::category::all | C; |
22 | SResult|= std::locale::category::all; |
23 | SResult = std::locale::category::all ^ C; |
24 | SResult^= std::locale::category::all; |
25 | |
26 | // std::ctype_base::mask |
27 | std::ctype_base::mask M = std::ctype_base::mask::punct; |
28 | |
29 | SResult = std::ctype_base::mask::space | std::ctype_base::mask::print; |
30 | SResult = std::ctype_base::mask::cntrl & std::ctype_base::mask::upper; |
31 | SResult = std::ctype_base::mask::lower ^ std::ctype_base::mask::alpha; |
32 | SResult|= std::ctype_base::mask::digit | std::ctype_base::mask::punct; |
33 | SResult&= std::ctype_base::mask::xdigit & std::ctype_base::mask::alnum; |
34 | SResult^= std::ctype_base::mask::alnum ^ std::ctype_base::mask::graph; |
35 | |
36 | SResult&= std::ctype_base::mask::space & M; |
37 | SResult|= std::ctype_base::mask::space | M; |
38 | SResult^= std::ctype_base::mask::space ^ M; |
39 | |
40 | // std::ios_base::fmtflags |
41 | std::ios_base::fmtflags F = std::ios_base::fmtflags::floatfield; |
42 | |
43 | SResult = std::ios_base::fmtflags::dec | std::ios_base::fmtflags::oct; |
44 | SResult = std::ios_base::fmtflags::hex & std::ios_base::fmtflags::basefield; |
45 | SResult = std::ios_base::fmtflags::left ^ std::ios_base::fmtflags::right; |
46 | SResult|= std::ios_base::fmtflags::internal | std::ios_base::fmtflags::adjustfield; |
47 | SResult&= std::ios_base::fmtflags::scientific & std::ios_base::fmtflags::fixed; |
48 | SResult^= std::ios_base::fmtflags::floatfield ^ std::ios_base::fmtflags::boolalpha; |
49 | SResult = std::ios_base::fmtflags::showbase | std::ios_base::fmtflags::showpoint; |
50 | SResult = std::ios_base::fmtflags::showpos & std::ios_base::fmtflags::skipws; |
51 | SResult = std::ios_base::fmtflags::unitbuf ^ std::ios_base::fmtflags::uppercase; |
52 | |
53 | SResult|= std::ios_base::fmtflags::unitbuf | F; |
54 | SResult&= std::ios_base::fmtflags::unitbuf & F; |
55 | SResult^= std::ios_base::fmtflags::unitbuf ^ F; |
56 | |
57 | // std::ios_base::iostate |
58 | std::ios_base::iostate S = std::ios_base::iostate::goodbit; |
59 | |
60 | SResult^= std::ios_base::iostate::goodbit | std::ios_base::iostate::badbit; |
61 | SResult|= std::ios_base::iostate::failbit & std::ios_base::iostate::eofbit; |
62 | SResult&= std::ios_base::iostate::failbit ^ std::ios_base::iostate::eofbit; |
63 | |
64 | SResult = std::ios_base::iostate::goodbit | S; |
65 | SResult = std::ios_base::iostate::goodbit & S; |
66 | SResult = std::ios_base::iostate::goodbit ^ S; |
67 | |
68 | // std::ios_base::openmode |
69 | std::ios_base::openmode B = std::ios_base::openmode::binary; |
70 | |
71 | SResult = std::ios_base::openmode::app | std::ios_base::openmode::binary; |
72 | SResult = std::ios_base::openmode::in & std::ios_base::openmode::out; |
73 | SResult = std::ios_base::openmode::trunc ^ std::ios_base::openmode::ate; |
74 | |
75 | SResult&= std::ios_base::openmode::trunc | B; |
76 | SResult^= std::ios_base::openmode::trunc & B; |
77 | SResult|= std::ios_base::openmode::trunc ^ B; |
78 | } |
79 | |
80 | void still_forbidden() { |
81 | // std::locale::category |
82 | unsigned int UResult = 0u; |
83 | int SResult = 0; |
84 | |
85 | SResult = std::ctype_base::mask::print ^ 8u; |
86 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
87 | SResult = std::ctype_base::mask::cntrl | 8; |
88 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
89 | SResult = std::ctype_base::mask::upper & 8; |
90 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
91 | SResult = std::ctype_base::mask::lower ^ -8; |
92 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
93 | |
94 | // Staying within the allowed standard types is ok for bitwise assignment |
95 | // operations. |
96 | std::ctype_base::mask var = std::ctype_base::mask::print; |
97 | SResult<<= std::ctype_base::mask::upper; |
98 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
99 | SResult>>= std::ctype_base::mask::upper; |
100 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
101 | SResult &= std::ctype_base::mask::upper; |
102 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
103 | SResult |= std::ctype_base::mask::upper; |
104 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
105 | SResult ^= std::ctype_base::mask::upper; |
106 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
107 | |
108 | UResult = std::locale::category::collate << 1u; |
109 | UResult = std::locale::category::ctype << 1; |
110 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
111 | UResult = std::locale::category::monetary >> 1u; |
112 | UResult = std::locale::category::numeric >> 1; |
113 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
114 | |
115 | UResult = ~std::locale::category::messages; |
116 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
117 | SResult = ~std::locale::category::all; |
118 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
119 | |
120 | // std::ctype_base::mask |
121 | UResult = std::ctype_base::mask::space | 8; |
122 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
123 | UResult = std::ctype_base::mask::print & 8u; |
124 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
125 | UResult = std::ctype_base::mask::cntrl ^ -8; |
126 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
127 | |
128 | UResult = std::ctype_base::mask::upper << 1; |
129 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
130 | UResult = std::ctype_base::mask::lower << 1u; |
131 | UResult = std::ctype_base::mask::alpha >> 1u; |
132 | UResult = std::ctype_base::mask::digit >> 1u; |
133 | |
134 | UResult = ~std::ctype_base::mask::punct; |
135 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
136 | SResult = ~std::ctype_base::mask::xdigit; |
137 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
138 | |
139 | // std::ios_base::fmtflags |
140 | UResult = std::ios_base::fmtflags::dec | 1; |
141 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
142 | UResult = std::ios_base::fmtflags::oct & 1u; |
143 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
144 | UResult = std::ios_base::fmtflags::hex ^ -1; |
145 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
146 | |
147 | UResult = std::ios_base::fmtflags::basefield >> 1; |
148 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
149 | UResult = std::ios_base::fmtflags::left >> 1u; |
150 | UResult = std::ios_base::fmtflags::right << 1; |
151 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
152 | UResult = std::ios_base::fmtflags::internal << 1u; |
153 | |
154 | UResult = ~std::ios_base::fmtflags::adjustfield; |
155 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
156 | SResult = ~std::ios_base::fmtflags::scientific; |
157 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
158 | |
159 | // std::ios_base::iostate |
160 | UResult = std::ios_base::iostate::goodbit | 8; |
161 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
162 | UResult = std::ios_base::iostate::badbit & 8u; |
163 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
164 | UResult = std::ios_base::iostate::failbit ^ -8; |
165 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
166 | |
167 | UResult = std::ios_base::iostate::eofbit << 1; |
168 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
169 | UResult = std::ios_base::iostate::goodbit << 1u; |
170 | UResult = std::ios_base::iostate::badbit >> 1; |
171 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
172 | UResult = std::ios_base::iostate::failbit >> 1u; |
173 | |
174 | UResult = ~std::ios_base::iostate::eofbit; |
175 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
176 | SResult = ~std::ios_base::iostate::goodbit; |
177 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
178 | |
179 | // std::ios_base::openmode |
180 | UResult = std::ios_base::app | 8; |
181 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
182 | UResult = std::ios_base::binary & 8u; |
183 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
184 | UResult = std::ios_base::in ^ -8; |
185 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
186 | |
187 | UResult = std::ios_base::out >> 1; |
188 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
189 | UResult = std::ios_base::trunc >> 1u; |
190 | UResult = std::ios_base::ate << 1; |
191 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a binary bitwise operator |
192 | UResult = std::ios_base::ate << 1u; |
193 | |
194 | UResult = ~std::ios_base::openmode::app; |
195 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
196 | SResult = ~std::ios_base::openmode::binary; |
197 | // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use of a signed integer operand with a unary bitwise operator |
198 | } |
199 |