On 09/05/16 13:23, Joseph Myers wrote: > On Sun, 4 Sep 2016, Bernd Edlinger wrote: > >> good to have as well. But this code would still be suspicious >> even if (x << y) is put in parentheses, because the shift count does >> not change the result of the condition, as the integer overflow is >> undefined behavior, and if it does not have side effects or does >> not throw something, it can even be optimized away. > > It's defined in GNU C (when the shift count is nonnegative and less than > the width of the type) - we document that we do not optimize on the basis > of it being undefined (although ubsan will still detect it). >
Oh, good to know, thanks for this info. Fortunately this will only be a warning, no optimization. But I think the reasoning is still correct, left shifting in a boolean context is suspicious, even if -fwrapv may make it defined. Do you agree? Bernd.