[PATCH] D129570: [clang-tidy] Add new clang-tidy check to find implicit conversions from enum to integer.

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 15:16:42 PDT 2022


njames93 removed reviewers: artem.tamazov, yaxunl, carlosgalvezp, MaskRay, mstorsjo, balazske.
njames93 added a comment.
This revision now requires review to proceed.

What is the motivation for requiring these to be the arguments of call or construct expressions?

Would be nice to add a note with an embedded fixit to silence this warning.
Something like this, though you may need to use the Lexer to get the correct location to insert the `)`.

  auto Note = diag(MatchedExpr->getBeginLoc(), "insert an explicit cast to silence this warning", DiagnosticIDs::Note);
  if (Result.Context->getLangOpts().CPlusPlus11)
    Note << FixItHint::CreateInsertion(MatchedExpr->getBeginLoc(), "static_cast<int>(")
             << FixItHint::CreateInsertion(MatchedExpr->getEndLoc().getLocWithOffset(1), ")");
  else
    Note << FixItHint::CreateInsertion(MatchedExpr->getBeginLoc(), "(int)");



================
Comment at: clang-tools-extra/clang-tidy/bugprone/EnumToIntCheck.cpp:28
+void EnumToIntCheck::check(const MatchFinder::MatchResult &Result) {
+  // FIXME: Add callback implementation.
+  const auto *MatchedExpr = Result.Nodes.getNodeAs<Expr>("x");
----------------
Remove this.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/EnumToIntCheck.h:18
+
+/// FIXME: Write a short description.
+///
----------------
FIXME


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

https://reviews.llvm.org/D129570



More information about the cfe-commits mailing list