http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48418
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED CC| |ebotcazou at gcc dot | |gnu.org Resolution| |WONTFIX --- Comment #1 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2011-04-02 21:06:47 UTC --- > int x=1000; > x>>=(sizeof(int)<<3); > > x is still 1000 The warning is clear: t.cc: In function 'void foo()': t.cc:4:22: warning: right shift count >= width of type This invokes undefined behavior, any result is acceptable. > In some cases bit shift operator used with variable (not constant) and > compiler > didnot show warning. My opinion is that result must be 0. The compiler cannot warn about values computed only at run time. If the shift amount is >= width of type at run time, this also invokes undefined behavior.