[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

Mike Crowe via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 9 03:26:37 PDT 2025


================
@@ -207,13 +207,9 @@ FormatStringConverter::FormatStringConverter(
       ArgsOffset(FormatArgOffset + 1), LangOpts(LO) {
   assert(ArgsOffset <= NumArgs);
   FormatExpr = llvm::dyn_cast<StringLiteral>(
-      Args[FormatArgOffset]->IgnoreImplicitAsWritten());
+      Args[FormatArgOffset]->IgnoreUnlessSpelledInSource());
 
-  if (!FormatExpr || !FormatExpr->isOrdinary()) {
-    // Function must have a narrow string literal as its first argument.
-    conversionNotPossible("first argument is not a narrow string literal");
-    return;
-  }
+  assert(FormatExpr && FormatExpr->isOrdinary());
----------------
mikecrowe wrote:

Fair enough. TBH I'm not sure that I can completely understand it myself and that's why I wrote lots of tests to try to catch all the cases.

My hand-wavy explanation is that `FormatStringConverter` wants to work on the string literal (as it is written in the source code) rather than any type that string literal may have been implicitly converted to (which aren't written in the source code) in order to be passed to the function being converted.

https://github.com/llvm/llvm-project/pull/142312


More information about the cfe-commits mailing list