This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR 35635 -Wconversion problematic with bitfields
2008/8/4 Joseph S. Myers <joseph@codesourcery.com>:
> On Fri, 1 Aug 2008, Manuel López-Ibáñez wrote:
>
>> The following patch fixes PR 35635 by doing two things:
>>
>> 1) Boolean expressions are ignored. I cannot think of a testcase where
>> an implicit conversion from boolean to another type loses information.
>> Since C front-end uses integer_type for boolean expressions, not
>> ignoring boolean expressions led to unwanted warnings.
>
> It doesn't lose information - but it does change the value if you put it
> in a signed:1 bit-field (which can hold the values 0 and -1).
Do boolean expressions in C have either 0 or 1 values? AFAIK, they are
either zero or non-zero. So I cannot see how assigning to a unsigned:1
bit-field is more correct than assigning to a signed:1 bit-field.
Moreover, internally GCC's C FE uses a "signed int" for boolean
expressions (which is why this works in C++ but not in C), so signed:1
seems actually more correct. I am afraid that such a special case may
be frequently triggered in real-world code if the use of int:1 or even
char:1 is widespread.
Anyway, I don't have a strong opinion either way, so I will implement
whatever is decided.
Cheers,
Manuel.