[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 27 00:22:55 PDT 2023
PiotrZSL added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:28
+ ReplacementPrintFunction(Options.get("PrintFunction", "std::print")) {
+ PrintfLikeFunctions.push_back("printf");
+ PrintfLikeFunctions.push_back("absl::PrintF");
----------------
NOTE: Consider using fully qualified names, like `::printf`
================
Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:45
+ Finder->addMatcher(
+ traverse(TK_AsIs,
+ callExpr(callee(functionDecl(matchers::matchesAnyListedName(
----------------
TK_IgnoreUnlessSpelledInSource should be fine for this.
================
Comment at: clang-tools-extra/clang-tidy/modernize/PrintfToStdPrintCheck.cpp:68
+ DiagnosticBuilder Diag =
+ diag(PrintfCall->getBeginLoc(), "Replace %0 with '%1'")
+ << OldFunction->getIdentifier() << ReplacementPrintFunction;
----------------
start warning with lower case, and maybe something like "use %0 instead of %1" (or whatever)
================
Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.h:32-47
+ const ASTContext *Context;
+ bool ConversionPossible = true;
+ bool FormatStringNeededRewriting = false;
+ size_t PrintfFormatStringPos = 0U;
+ StringRef PrintfFormatString;
+
+ const Expr *const *Args;
----------------
NOTE: Consider re-ordering private-public, like in other files, to first put public stuff, then private.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149280/new/
https://reviews.llvm.org/D149280
More information about the cfe-commits
mailing list