[Bug c/39170] provide an option to silence -Wconversion warnings for bit-fields

manu at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jan 4 17:53:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39170

--- Comment #13 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 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.



More information about the Gcc-bugs mailing list