https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764
Eric Gallager <egall at gwmail dot gwu.edu> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |egall at gwmail dot gwu.edu --- Comment #1 from Eric Gallager <egall at gwmail dot gwu.edu> --- Remember, x |= y is the same as x = (x | y). So if we rewrite the problematic conversions like that, it becomes clearer where the warning is really pointing: $ /usr/local/bin/gcc -c conversion_bug.c -Wconversion conversion_bug.c: In function ‘_setbit’: conversion_bug.c:4:13: warning: conversion to ‘unsigned char’ from ‘int’ may alter its value [-Wconversion] b[i / 8] = (b[i / 8] | (unsigned char)(1 << (i % 8))); ^ conversion_bug.c: In function ‘_mask_stupid’: conversion_bug.c:15:9: warning: conversion to ‘unsigned char’ from ‘int’ may alter its value [-Wconversion] b[i] = (b[i] | (unsigned char)i); ^ If you cast the entire expression after it has been re-written like that, the warning goes away: b[i / 8] = (unsigned char)(b[i / 8] | (unsigned char)(1 << (i % 8))); b[i] = (unsigned char)(b[i] | (unsigned char)i); (no warnings generated for either of those)