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

Aaron Ballman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 18 07:44:42 PDT 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp:35
+                                      hasSourceExpression(IsFloatExpr),
+                                      unless(hasParent(castExpr())))
+                         .bind("cast"),
----------------
courbet wrote:
> aaron.ballman wrote:
> > I believe this code will not diagnose under this check -- is that intended as a way to silence the check?
> > ```
> > i += (double)0.5;
> > ```
> Did you mean `(int)0.5` ?
> 
> Yes, the user essentially told us they knew what they were doing. I've added an explicit test for this.
I truly meant `(double)0.5` -- where the cast has no impact on the narrowing conversion, but the check still doesn't diagnose because there's an explicit cast present. Should the check be checking for explicit casts to the narrowed type?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38455





More information about the llvm-commits mailing list