Re: [PATCH 1/2] fix clang -Wconstant-conversion with bit fields
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 16, 2013, 23:46 UTC
- Message-ID
- <7vlibsvghh.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <7vpq14vglu.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 27 quoted lines
> Antoine Pelisse <apelisse@gmail.com> writes:
>
>> clang incorrectly reports a constant conversion warning (implicit
>> truncation to bit field) when using the "flag &= ~FLAG" form, because
>> ~FLAG needs to be truncated.
>>
>> Convert this form to "flag = flag & ~FLAG" fixes the issue as
>> the right operand now fits into the bit field.
>
> If the "clang incorrectly reports" is already recognised by clang
> folks as a bug to be fixed in clang, I'd rather not to take this
> patch.
>
> I do not think it is reasonable to expect people to remember that
> they have to write "flags &= ~TO_DROP" in a longhand whenever they
> are adding new code that needs to do bit-fields, so even if this
> patch makes clang silent for the _current_ code, it will not stay
> that way. Something like
>
> #define FLIP_BIT_CLR(fld,bit) do { \
> typeof(fld) *x = &(fld); \
> *x = *x & (~(bit)); \
> } while (0)
>
> may be more palapable but not by a large margin.
>
> Yuck.Double yuck. I meant palatable.
In any case, I see somebody reports that more recent clang does not have this bug in the near-by message, so let's forget about this issue.
Thanks.