[Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764 Marcin Ślusarz changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |DUPLICATE --- Comment #5 from Marcin Ślusarz --- Heh, I took a closer look and this bug indeed is a duplicate. -Wconversion is quite useless in its current form. *** This bug has been marked as a duplicate of bug 40752 ***
[Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764 Manuel López-Ibáñez changed: What|Removed |Added CC||manu at gcc dot gnu.org --- Comment #6 from Manuel López-Ibáñez --- (In reply to Marcin Ślusarz from comment #5) > Heh, I took a closer look and this bug indeed is a duplicate. -Wconversion > is quite useless in its current form. > > *** This bug has been marked as a duplicate of bug 40752 *** Being the main author of Wconversion, I do agree with this sentiment. You'll see there is a patch there to alleviate this issue, but I couldn't manage to get it approved and now I don't have the time to invest on this issue. If you want to see this fixed, your best option is to adopt the patch, update it, test it and try to get it approved. Comparisons with how Clang and other compilers behave would be useful but they should not be the basis of your argumentation. When arguing for a change, try to be smart and see the point of view of the other side and address that convincingly.
[Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764 --- Comment #4 from Marcin Ślusarz --- The issue is similar. However what I described in this bug can be considered a regression, because gcc 4.9 behaves correctly. Bug 40752 is 6 years old.
[Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764 --- Comment #2 from Marcin Ślusarz --- That's still gcc bug.
[Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764 --- Comment #3 from Eric Gallager --- Wait actually I think this might be a dup of bug 40752
[Bug c/67764] -Wconversion generates false warnings for bitmask+cast expressions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67764 Eric Gallager changed: What|Removed |Added CC||egall at gwmail dot gwu.edu --- Comment #1 from Eric Gallager --- 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)