[all-commits] [llvm/llvm-project] 4530c3: [clang-tidy] Fix cppcoreguidelines-narrowing-conve...
Nathan James via All-commits
all-commits at lists.llvm.org
Sat Apr 15 08:08:02 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 4530c3bc4897f6633577de07b61ceb1bf7e79f50
https://github.com/llvm/llvm-project/commit/4530c3bc4897f6633577de07b61ceb1bf7e79f50
Author: Nathan James <n.james93 at hotmail.co.uk>
Date: 2023-04-15 (Sat, 15 Apr 2023)
Changed paths:
M clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
M clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
Log Message:
-----------
[clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive
Fix https://llvm.org/PR49498.
The check notices 2 sides of a conditional operator have types with a different constness and so tries to examine the implicit cast.
As one side is infinity, the float narrowing detection sees when its casted to a double(which it already was) it thinks the result is out of range.
I've fixed this by just disregarding expressions where the builtin type(without quals) match as no conversion would take place.
However this has opened a can of worms. Currenty `float a = std::numeric_limits<double>::infinity();` is marked as narrowing.
Whats more suspicious is `double a = std::numeric_limits<float>::infinity();` is also marked as narrowing.
It could be argued `double inf -> float inf` is narrowing, but `float inf -> double inf` definitely isnt.
Reviewed By: carlosgalvezp
Differential Revision: https://reviews.llvm.org/D98416
More information about the All-commits
mailing list