http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59852
--- Comment #8 from Josh Triplett <josh at joshtriplett dot org> --- (In reply to Josh Triplett from comment #7) > (In reply to Josh Triplett from comment #4) > > Also note that arithmetic operations between a bitwise and a known-zero > > value do not warn. > > > > The warning on ~ of a value smaller than int only occurs if the value is not > > subsequently stuffed back into the same bitwise type. For instance, this > > does not warn: > > > > typedef unsigned short __attribute__((bitwise)) le16; > > > > le16 i, j; > > > > le16 k = ~i | j; > > To elaborate on this with some implementation details of Sparse: applying ~ > to a bitwise type smaller than an int produces a value of a corresponding > bitwise type with the added attribute "fouled". Bitwise operations > propagate the fouled bit if either operand has it, without warning. == and > != will warn about fouled types. Assignments or conversions to the original > unfouled bitwise type will work without warning, discarding the fouled bit. > And any arithmetic operation that would warn about a bitwise type will warn > about a fouled type, complaining that the type degraded to "int". One more detail: bitwise '&' of two fouled bitwise types will work and produce the same fouled type; but bitwise '&' of a bitwise type and the corresponding fouled bitwise type will produce the unfouled bitwise type. For details, see commit d24967cb847b7a04920698a9053ea8195046a831 in Sparse by Al Viro: Basically, we delay reporting an error on ~<short bitwise> for as long as possible in hope that taint will be cleansed later. Exact rules follow: * ~short_bitwise => corresponding fouled * any arithmetics that would be banned for bitwise => same warning as if we would have bitwise * if t1 is bitwise type and t2 - its fouled analog, then t1 & t2 => t1, t1 | t2 => t2, t1 ^ t2 => t2. * conversion of t2 to t1 is silent (be it passing as argument or assignment). Other conversions are banned. * x ? t1 : t2 => t2 * ~t2 => t2 (_not_ t1; something like ~(x ? y : ~y) is still fouled) * x ? t2 : t2 => t2, t2 {&,|,^} t2 => t2 (yes, even ^ - same as before). * x ? t2 : constant_valid_for_t1 => t2 * !t2 => warning, ditto for comparisons involving t2 in any way. * wrt casts t2 acts exactly as t1 would. * for sizeof, typeof and alignof t2 acts as promoted t1. Note that fouled can never be an lvalue or have types derived from it - can't happen.