rspec/rules/S2887/rule.adoc

15 lines
543 B
Plaintext

== Why is this an issue?
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
[source,text]
----
int i = -1;
short s = (short)i >>> 4; /// Noncompliant
----