[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Eric Gallager changed: What|Removed |Added CC||in-gcc at baka dot org --- Comment #22 from Eric Gallager --- *** Bug 95213 has been marked as a duplicate of this bug. ***
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Eric Gallager changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=87406 --- Comment #21 from Eric Gallager --- Possibly related to bug 87406 which requests adding clang's -Wbitfield-constant-conversion
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Eric Gallager changed: What|Removed |Added Status|NEW |ASSIGNED --- Comment #20 from Eric Gallager --- (In reply to Eric Gallager from comment #19) > (In reply to Manuel López-Ibáñez from comment #11) > > (In reply to comment #10) > > > However, with so many lines of legacy code out there using bit-filed that > > > have > > > been proven to work, it doesn't make sense to revisit/modify them. Would > > > it > > > be possible for gcc to provide a -Wbitfield-conversion flag in new > > > releases > > > and make 39170 an enhancement (preferably high priority)? > > > > Seriously, I am not the "maintainer" of GCC diagnostics > > That's David Malcolm; adding him on cc ...and since he's now made himself the assignee, changing status to ASSIGNED
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Eric Gallager changed: What|Removed |Added CC||dmalcolm at gcc dot gnu.org --- Comment #19 from Eric Gallager --- (In reply to Manuel López-Ibáñez from comment #11) > (In reply to comment #10) > > However, with so many lines of legacy code out there using bit-filed that > > have > > been proven to work, it doesn't make sense to revisit/modify them. Would it > > be possible for gcc to provide a -Wbitfield-conversion flag in new releases > > and make 39170 an enhancement (preferably high priority)? > > Seriously, I am not the "maintainer" of GCC diagnostics That's David Malcolm; adding him on cc
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 --- Comment #18 from Florin Iucha --- Even this version creates a warning: #include struct foo { unsigned bar: 30; unsigned fill: 2; }; struct foo test(uint32_t value) { struct foo foo; foo.bar = (value >> 2) & 0x3fffU; return foo; }
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Florin Iucha changed: What|Removed |Added CC||florin.iucha at amd dot com --- Comment #17 from Florin Iucha --- Warning if the code 'may alter its value' is one thing. Can we have GCC at least not warn if it knows it will not alter the value? For example, compiling struct foo { unsigned bar: 30; unsigned fill: 2; }; struct foo test(unsigned value) { struct foo foo; foo.bar = value >> 2; return foo; } This yields: test.c: In function ‘test’: test.c:11:14: warning: conversion to ‘unsigned int:30’ from ‘unsigned int’ may alter its value [-Wconversion] foo.bar = value >> 2; ^ Tested with GCC 5.4.0 and 7.2.
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Albi changed: What|Removed |Added CC||albrecht.guendel at web dot de --- Comment #16 from Albi --- Here is a type safe C++ solution: template union NBitValueUnion { static_assert((sizeof(T)*8) > N, "Strange Bitfield Width"); private: const T Data; public: struct { const T Value : N; const T : (sizeof(T)*8-N); }; NBitValueUnion(const T& _Data): Data(_Data) {} }; template const NBitValueUnion NBitValue(const T& _Data) { return NBitValueUnion(_Data); } Usage: Bitfield.Member = VariableName; //Triggers -Wconversion Bitfield.Member = NBitValue(VariableName).Value; //Silent. Unfortnunately it triggers -Waggregate-return (which is a topic for it self since its a type thats fits in a register, so its an aggregate.. but not in hardware.) Any improvements are welcome.
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Manuel López-Ibáñez changed: What|Removed |Added Keywords||diagnostic --- Comment #15 from Manuel López-Ibáñez --- (In reply to Eric Gallager from comment #14) > Just an FYI, there's a proposal to add a -Wbitfield-conversion flag that > does something slightly different than the behavior described in this issue; > for reference, see: https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00723.html > I'd be fine with it doing either the behavior in that patch, or the behavior > from this issue... I think the two behaviors are orthogonal. People still need an option that refines -Wconversion and allows silencing it for bit-fields. I will prefer if this option is called -Wbitfield-conversion and the other proposal is called something else (-Wbitfield-promotion ? -Wbitfield-shift ?). But whoever does the implementation work, will decide the name.
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 Eric Gallager changed: What|Removed |Added CC||egall at gwmail dot gwu.edu --- Comment #14 from Eric Gallager --- (In reply to Jeng-Liang Tsai from comment #10) > Would it be possible for gcc to provide a -Wbitfield-conversion flag in new > releases and make 39170 an enhancement (preferably high priority)? Just an FYI, there's a proposal to add a -Wbitfield-conversion flag that does something slightly different than the behavior described in this issue; for reference, see: https://gcc.gnu.org/ml/gcc-patches/2014-11/msg00723.html I'd be fine with it doing either the behavior in that patch, or the behavior from this issue...
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 --- Comment #13 from Manuel López-Ibáñez 2013-01-04 17:53:00 UTC --- (In reply to comment #12) > Is there any resolution to this issue? We need to move to a more recent > version > of gcc, but are still stuck at gcc 4.2.4. I think the best option would be to have a GCC extension for casting bit-field types (int:2) so they can be used to silence false positives. But this may be rejected by the C/C++ FE maintainers, so unless you get their approval, I wouldn't try to pursue it. The second best option, and probably easier to implement, is to have a new option -Wconversion-bitfields that gives the Wconversion warning for bitfields and use that to control the warning code like: if (unsafe_conversion_p (type, expr, true)) warning_at (loc, TYPE_IS_BITFIELD(type) ? OPT_Wconversion_bitfield : OPT_Wconversion, "conversion to %qT alters %qT constant value", type, expr_type); return; I don't even know if TYPE_IS_BITFIELD exists or there is an equivalent API. Personally, I have no free time to work on this, so someone else will have to do it. I can give some hints on what you would need to do to implement it if someone is interested and needs guidance.
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170 --- Comment #12 from Tom Geocaris 2013-01-04 17:32:22 UTC --- Is there any resolution to this issue? We need to move to a more recent version of gcc, but are still stuck at gcc 4.2.4. I looked at gcc 4.7.2 but behavior is the same and I don't see an option to suppress these warnings.
[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields
--- Comment #11 from manu at gcc dot gnu dot org 2010-03-06 12:18 --- (In reply to comment #10) > However, with so many lines of legacy code out there using bit-filed that have > been proven to work, it doesn't make sense to revisit/modify them. Would it > be > possible for gcc to provide a -Wbitfield-conversion flag in new releases and > make 39170 an enhancement (preferably high priority)? Seriously, I am not the "maintainer" of GCC diagnostics or even Wconversion. Anyone can contribute! Yes, it may be possible to provide such an option. I am not against such an option and even if I were I cannot stop you from implementing it and getting it approved by GCC maintainers. I don't know how much work it would be to implement it, and out of kindness I might invest some of my free time to try to do it for GCC 4.6. But even if I might try, that won't happen before summer almost for sure, and then GCC 4.6 won't be available before late next year. -- manu at gcc dot gnu dot org changed: What|Removed |Added Severity|normal |enhancement Status|WAITING |NEW Ever Confirmed|0 |1 Last reconfirmed|-00-00 00:00:00 |2010-03-06 12:18:44 date|| Summary|cannot silence -Wconversion |provide an option to silence |warnings for bit-fields |-Wconversion warnings for ||bit-fields http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170