------- Comment #1 from pinskia at gcc dot gnu dot org 2007-03-18 05:29 ------- You are wrong. The casts are correct as char + char in C is actually defined as (int)(char) + (int) (char) aka promoted to int while doing the addition so what the optimizers do when it sees (char)((int)(char) + (int)(char)), it changes the addition to be (unsigned char)(char) + (unsigned char)(char) so the addition's overflow is defined as being wrapping instead of being undefined.
-- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31248