------- Comment #7 from john dot carter at tait dot co dot nz 2009-02-23 23:53 ------- R Guenther said... > (int)u1 == (int)(u8_t)(~(int)u2) > > that we do not warn for the first case is because it is optimized to > u1 == ~u2 before. > > Why do you think the warning is incorrect? -----------------------------------------------
I would expect u2 to be promoted to a 4 byte int ~ to do the ones complement on a 4 byte int (unsigned char)~u2 to truncate to one byte discarding the most significant 3 bytes and then the result get promoted to an int to evaluate the == ie. The cast cannot get optimized away, it's not a null op, it discards the most significant bytes. ie. (int)(unsigned char)~(int)u2 is not equivalent to ~(int)u2 ie. This is a bug -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38341