Alex said:
The standard very clearly intends to specify the behaviour.
Unfortunately, not in a completely unambiguous manner - hence
the defect report.
Of course it should enforce a behavior. However that behavior
should be both rational and agree with existing practice. It seems
that existing practice already varies.
The wording of the standard is easily understood for types subject
to integer promotion other than bit-fields, and defines different
behaviour to what you suggest should apply to bit-fields. I believe
the intention was for the two to be consistent - bit-fields should
be viewed as a "small" type like unsigned char and unsigned short -
and this agrees with the response to the defect report.
Others, and I, have pointed out the anomalies that can result from
this attitude. The opportunity should be taken to clean this up
without contravening any earlier standard. C is already a morass
of insecurities, there is no need to add another.
One ridiculous result of this attitude is that a 1 bit field,
whether declared as int or unsigned int, would always be treated as
-1 or 0. This is contrary to the usual C practice. The
opportunity exists to ensure that booleans stored in bit fields are
properly expanded. Or should we have to write !!x for any boolean
x stored in a bitfield?
Just like a 16-bit unsigned short.
The only difference between what you suggest and what most people
seem to think the standard says is that for some unsigned
bit-fields (those with max value <= INT_MAX), the latter says
promote to signed int whereas you say promote to unsigned int.
However, code generated for promotion of an unsigned bit-field
to signed int is identical to that for promotion of an unsigned
bit-field to unsigned int, provided the representations of all
positive signed int values are identical to the same unsigned
int value. This is normally, if not always, the case.
No, it is not. It is dependant on the value of the sign bit of the
restricted bit field, if you insist on the so called 'value
preserving' interpretation here rather than 'signed preserving'.
Therefore I fail to see how considering code generation, rational
or otherwise, could lead you to a conclusion either way on this
issue.
Simple - signed preservation leads to consistent interpretation by
the user, minimization of generated code, and reduction of code in
the code generator. Due to the ambiguity of the present standard
the opportunity exists to specify this correctly. Do so.