{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/23421","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/23421/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/23421/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/23421/events","html_url":"https://github.com/rust-lang/rust/issues/23421","id":62208311,"number":23421,"title":"Inaccuracies in the reference about bitshifts and overflows","user":{"login":"simias","id":7925386,"avatar_url":"https://avatars.githubusercontent.com/u/7925386?v=3","gravatar_id":"","url":"https://api.github.com/users/simias","html_url":"https://github.com/simias","followers_url":"https://api.github.com/users/simias/followers","following_url":"https://api.github.com/users/simias/following{/other_user}","gists_url":"https://api.github.com/users/simias/gists{/gist_id}","starred_url":"https://api.github.com/users/simias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simias/subscriptions","organizations_url":"https://api.github.com/users/simias/orgs","repos_url":"https://api.github.com/users/simias/repos","events_url":"https://api.github.com/users/simias/events{/privacy}","received_events_url":"https://api.github.com/users/simias/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-16T21:00:09Z","updated_at":"2015-03-16T21:00:09Z","closed_at":null,"body":"The references states that `>>` is a logical right shift, however it seems that it behaves like an *arithmetic* right shift for signed integers. For instance the following snippet prints `-2`:\r\n\r\n```rust\r\nlet i = -4i32;\r\n\r\nprintln!(\"{}\", i >> 1);\r\n```\r\n\r\nA logical right shift should produce `2147483646` (assuming 2's complement representation which I think rust guarantees?).\r\n\r\nIn the same spirit the reference does not say if shifting outside the range of an integer is defined. From my quick test it doesn't appear to be:\r\n\r\n```rust\r\nlet i = 10u32;\r\nlet j = 200u32;\r\n\r\nprintln!(\"{}\", i << j);\r\n```\r\n\r\nThis prints garbage on my computer and on the playpen, so I assume it's UB or at least UV (it doesn't trigger the overflow check in debug builds though, maybe it should?)\r\n\r\nOn a similar topic the references also states that the following behaviours are safe:\r\n* Unsigned integer overflow (well-defined as wrapping)\r\n* Signed integer overflow (well-defined as two's complement representation wrapping)\r\n\r\nI believe that's not true anymore."}}