Note that there are some explanatory texts on larger screens.

plurals
  1. POCatching overflow of left shift of constant 1 using compiler warning?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. CONo matter what size int is, if bar is too big then the shift is undefined (I think. Some kind of bad, anyway). You seem to be asking for the compiler to warn you about a variable second operand to shift on an int. But you say the problem is that '1' is not long: do you want no warning about a variable shift on a long? I don't see why compiler-writers would expect that warning to be useful, and general warnings about variable second operand to << would result in vast numbers of false positives.
      singulars
    2. CO@onebyone: Assuming `int` is 32 bits and `long long` is 64, `~(foo + (1<<bar))` only works for `0<=bar<32`, while `~(foo + (1LL<<bar))` works for `0<=bar<64`. I assume that OP wants a warning when the former is written instead of the latter.
      singulars
    3. COSure, but would he want that warning in cases where foo is an int and bar is logically constrained (but not by type) to be either 1 or 2? How about where foo is a long long and bar is 1 or 2? Warnings for multiplying or adding bar to any signed constant, since the result of overflow is undefined? The compiler usually can't identify the logical constraints, so I'd expect any such warnings to be highly prone to false positives. Doesn't mean it's a bad idea, I'm just speculating why it's hard to define what it should be, and low priority for compiler writers anyway.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload