Skip to content

ineffective-bitwise-zero

Detect bitwise operations whose zero operand fixes the result.

Updated View as Markdown

Default severity: warning

For integers, x & 0 is always zero while x | 0 and x ^ 0 are always x. A zero-valued flag declared directly with iota often indicates that 1 << iota was intended.

Shift-by-zero expressions are accepted because they commonly appear in regular bit-field layouts alongside shifts by 8, 16, and so on.

Bad

unchanged := value ^ 0

Good

masked := value & mask
Navigation

Type to search…

↑↓ navigate↵ selectEsc close