patch - gcc-4.0 not c99 conforming when assigning scalar values to boolean bitfields
Geoffrey Keating
geoffk@geoffk.org
Thu Mar 31 23:00:00 GMT 2005
Fariborz Jahanian <fjahanian@apple.com> writes:
> gcc-4.0 is not c99 conforming when assigning scalar values to boolean
> bitfields.
> gcc-3.3 and g++4.0 are.
>
> From: ISO/IEC 9899:1999 (E)
>
> 6.3.1.2 Boolean type
>
> 1 When any scalar value is converted to _Bool, the result is 0 if the
> value compares equal to 0;
> otherwise, the result is 1.
>
> So, following test fails with gcc-4.0.
>
> struct bits {
> _Bool f2:6;
> } b;
> int main() {
> b.f2 = 17;
> return (b.f2 == 1 ? 0 : 1 );
> }
>
> Problem starts in c-decl.c's finish_struct routine which changes type
> of bitfields to a new type
> which can represent width of the bitfield. Here the fact that we have
> a boolean bit-field is lost.
> I fixed this problem by not doing this change for _Bool bitfields if
> size of _Bool is enough to contain
> width of the bitfield.
I don't think this change is completely right. What happens if 'f2'
has size 200? I think your change would see that 32 < 200 and will
have no effect.
So, I think you should delete the '< width' condition, and add an
extra testcase for a very large '_Bool' field; if that works, then the
patch is OK.
More information about the Gcc-patches
mailing list