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

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 24 07:17:00 PDT 2018


aaron.ballman added inline comments.


================
Comment at: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp:56-57
 
-void NarrowingConversionsCheck::check(const MatchFinder::MatchResult &Result) {
-  if (const auto *Op = Result.Nodes.getNodeAs<BinaryOperator>("op")) {
-    if (Op->getBeginLoc().isMacroID())
-      return;
-    diag(Op->getOperatorLoc(), "narrowing conversion from %0 to %1")
-        << Op->getRHS()->getType() << Op->getLHS()->getType();
+static bool isNarrower(const ASTContext *const Context, const QualType Lhs,
+                       const QualType Rhs) {
+  assert(Lhs->isRealType());     // Either integer or floating point.
----------------
Please drop the top-level `const` qualifiers (that's not something we do consistently elsewhere). Here and elsewhere.


================
Comment at: clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp:68
     return;
-  }
-  const auto *Cast = Result.Nodes.getNodeAs<ImplicitCastExpr>("cast");
-  if (Cast->getBeginLoc().isMacroID())
+  const auto LhsType = Op.getLHS()->getType();
+  const auto RhsType = Op.getRHS()->getType();
----------------
Do not use `auto` here as the type is not spelled out in the initialization (same elsewhere). You should also drop the top-level `const`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53488





More information about the cfe-commits mailing list