&gt; I can&#x27;t understand why e.g. use of an uninitialized variable or oversized shift amounts are UB<p>Probably some obscure architecture traps on oversized shifts or something similar. To correctly implement it you would first have to check if the shift lies inside the bounds with a branch. Branches are expensive - this is the powerful optimisation.