rspec/rules/S2887/rule.adoc

15 lines
543 B
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
2021-01-27 13:42:22 +01:00
Unsigned right shift (``++>>>++``) fills from the left with 0's, versus signed right shift (``++>>++``), which fills with the sign bit. There's no point in using ``++>>>++`` unless you care about the upper bits of the result, so casting a ``++>>>++``-ed value to a smaller type (which discards the upper bits) is likely a mistake. Either ``++>>++`` should have been used, or the cast was made in error.
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,text]
----
int i = -1;
short s = (short)i >>> 4; /// Noncompliant
----