mozilla/rust — Issue #1877: Inconsistent behavior for bitshifts by more than length of field
Author: bzbarsky
Created: 2012-02-21 16:46:36+00:00
State: open

Consider this testcase:

use std;
fn main() {
let i : u32 = (1u32 << 32u32);
std::io::println(#fmt("%d", i as int));
}

This prints 25187856 on my setup. If, on the other hand, I do something more like this:

use std;
fn main() {
let s : u32 = 0u32;
while (s < 40u32) {
let i : u32 = (1u32 << s);
std::io::println(
#fmt("shift: %d, result: %d", s as int, i as int));
s = s + 1u32;
}
}

then I get Java-like behavior; in particular one of the lines is:

shift: 32, result: 1

which totally doesn't match what happened with the shift by a literal!