------- Comment #4 from manu at gcc dot gnu dot org 2008-08-01 17:54 ------- To be honest, I am not sure what deserves a warning and what not in this testcase.
FOO is 19, ~FOO is -20. Therefore ushort x = ~FOO seems to deserve a warning (with -Wsing-conversion at least). x = x & -20 is handled as x = (int)x & -20. If x == 0xFFFF, this seems like the case above and probably deserves a warning. lv = lv & ~rv is seen as: <bit_and_expr type <integer_type int public SI size <integer_cst constant 32> unit size <integer_cst constant 4> arg 0 <nop_expr 0x2aaaab238940 type <integer_type int> arg 0 <indirect_ref type <integer_type short unsigned int> arg 0 <parm_decl lv>>> arg 1 <bit_not_expr type <integer_type int> arg 0 <nop_expr type <integer_type int> arg 0 <indirect_ref type <integer_type short unsigned int> tree_0 arg 0 <parm_decl rv>>>>> That is, we would need to peek inside each operand and recursively check whether the expressions/conversions are safe. I don't know if this is feasible at all and I personally don't know at this moment how to implement it properly. On the other hand, in mainline, I don't get any warnings for: x = x & ushort(~FOO); // -Wconversion x = x & ushort(~ushort(FOO)); // -Wconversion x &= static_cast<ushort>(~FOO); // -Wconversion So that seems fixed. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35852