[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: clang-10 warning in hash.c
From: |
Bruno Haible |
Subject: |
Re: clang-10 warning in hash.c |
Date: |
Mon, 27 Jan 2020 22:03:34 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; ) |
Paul Eggert wrote:
> In the past I've worked around problems like these by writing things
> like "SIZE_MAX + 1.0f <= new_candidate" instead of "SIZE_MAX <=
> new_candidate"
This may deserve a warning that adding 1.0f does not change the value.
> Presumably the Clang folks want us to insert a cast to 'float', e.g.,
> "(float) SIZE_MAX <= new_candidate". However, I dislike casts because
> they're too powerful.
And I dislike it because the transformation is correct only if
(float) SIZE_MAX >= SIZE_MAX. In the other case,
(float) SIZE_MAX < SIZE_MAX, the transformation is incorrect
[think of the particular value new_candidate = (float) SIZE_MAX].
The compiler should make correct transformations of comparisons;
that's not the job of the programmer.
> If there's no way to pacify Clang without casting, then I suggest
> disabling the warning instead.
I agree. When a compiler makes a normal and correct optimization,
we don't want to hear about it. Only when the compiler makes a
dangerous optimization, we want to see a warning.
Bruno