[PATCH] D53488: [clang-tidy] Catching narrowing from double to float.

Clement Courbet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 5 01:03:25 PST 2018


courbet added inline comments.


================
Comment at: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp:155
+  if (!LhsIntegerRange.Contains(IntegerConstant))
+    diag(SourceLoc, "narrowing conversion from %0 to %1") << RhsType << LhsType;
+  return true;
----------------
I think it would be clearer to have something like "narrowing conversion from %0 literal to %1"


================
Comment at: test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp:163
+  int i;
+  while (i) {
+    // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: narrowing conversion from 'int' to 'bool' [cppcoreguidelines-narrowing-conversions]
----------------
I think some people would not like to be warned on this (especially for the form `if (!returns_int())`, because the `!` does the cast). What about adding options to the check to disable some forms ?


================
Comment at: test/clang-tidy/cppcoreguidelines-narrowing-conversions.cpp:164
+  while (i) {
+    // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: narrowing conversion from 'int' to 'bool' [cppcoreguidelines-narrowing-conversions]
+  }
----------------
What about providing a fix for this one :
`while (i != 0) {`


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53488





More information about the cfe-commits mailing list