On Mon, 3 Nov 2025 19:12:43 GMT, Roger Riggs <[email protected]> wrote:

>> Hmm, obviously this is a judgement call and I'm curious what others think.
>> 
>> My opinion is that I still think there should be a warning for shifts of -1.
>> 
>> I mean, maybe to a _real_ hacker, then of course `foo << -1` makes perfect 
>> sense because it's just stating the "obvious" which is "shift the low order 
>> bit into the high order position and set all the other bits to zero", 
>> right?? :)
>> 
>> I just don't think the average Java programmer automatically understands 
>> that.
>> 
>> Yes, it's an idiom or "handy trick", but if hasn't attained the status of 
>> being universally recognized then it doesn't deserve a special exception.
>> 
>> On the other hand, excluding -1 from the warning would be less disruptive 
>> (at least, to the real hackers out there), and that has its own merits. So I 
>> don't have a super strong opinion about it.
>
> This might be worth a corpus scan to see how common it is to shift by -1 or 
> other constants, either int or long.
> Someone, might interpret `v << -1` as a right shift, is it more likely to 
> misinterpret it as using more than 5/6 bits of the shift or considering it 
> signed.

I am working on a corpus run, will take some days probably. But I am not sure 
if producing a warning for code that is "correct, but advanced use" is 
realistic. Maybe the line needs to be draw closer to "the code is probably 
buggy/highly suspicious".

@rgiulietti - thanks, the explanation makes sense.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27102#discussion_r2495062625

Reply via email to