[PATCH] D53488: [clang-tidy] Improving narrowing conversions

Guillaume Chatelet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 23 13:15:21 PST 2018


gchatelet marked an inline comment as done.
gchatelet added inline comments.


================
Comment at: test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp:42-44
   i += 2.0;
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: narrowing conversion from constant 'double' to 'int' [cppcoreguidelines-narrowing-conversions]
   i += 2.0f;
----------------
aaron.ballman wrote:
> gchatelet wrote:
> > aaron.ballman wrote:
> > > I don't think these should diagnose. They're both harmless as the literal values are exactly representable in the destination type.
> > Yes indeed they are harmless but why not write the correct literal in the first place?
> > I'm keeping these warnings for now. Let me know if you feel strongly about it.
> > Yes indeed they are harmless but why not write the correct literal in the first place?
> 
> Why force the user to modify their code when the behavior will be exactly the same as before?
> 
> > I'm keeping these warnings for now. Let me know if you feel strongly about it.
> 
> I don't feel very strongly on this case, but it seems needlessly chatty to me to diagnose code that's not incorrect. For instance, this code could exist in a (system) header file that the user doesn't have the ability to correct.
I've added a `WarnOnCastingLiterals` option to display them.
It's on by default.
Let me know if you have a better name, I'm not super happy with it.
Let me know if you think it should be off by default.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53488/new/

https://reviews.llvm.org/D53488





More information about the cfe-commits mailing list