[PATCH] D38455: [clang-tidy] new cppcoreguidelines-narrowing-conversions check.

Clement Courbet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 27 05:04:19 PDT 2018


courbet added a comment.

OK, here's an analysis of 100 instances of a check that would warn on all fully implicit (no C/static/reinterpret/...) casts from float/double to integral: link <https://docs.google.com/document/d/1X1ostfsvwEDD3I4LLSKgDIF131lAUElRUg2ONyr_Xjg/edit?usp=sharing>
I don't expect the analysis to be perfect, but that gives us a better idea of what to expect.

- A bit more than 1/3 of instances are OK and should be using a cast.
- A bit less than 1/4 of instances is brittle code and should use int types.
- The two false positive cases are easy to handle.
- I was surprised about the "truth value of float" one. I think we should provide a fix to turn `!f` this into `f != 0.0f`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38455





More information about the cfe-commits mailing list