[clang] [clang] Do not diagnose float-equal for 0 and 1 (PR #207288)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 8 07:00:28 PDT 2026
AaronBallman wrote:
> In my opinion, `0` and `INFINITY` should be allowed by default with this `-Wfloat-equal`, since you commonly want to guard against those values. Additionally, we could have a flag that restricts the use of `0`. As for other float values (other than `0` and `INFINITY`), maybe we should not allow them by default and provide a flag to allow exact float values, this way, people who intend to compare to the same bit pattern can still do so.
I think it's useful to find *all* direct comparisons of floating-point types regardless of value, which is the behavior of `-Wfloat-equal` in GCC. It's not that the comparison itself is invalid, it's that it's pointing out a potential algorithmic issue with the computations leading up to the comparison. e.g., https://godbolt.org/z/d69drsM95 But given that this has been Clang's behavior with this diagnostic for almost 20 years, I expect changing Clang to match GCC would be too disruptive. That suggests we need a new warning group, but naming the group will be a challenge.
https://github.com/llvm/llvm-project/pull/207288
More information about the cfe-commits
mailing list