[clang] [Sema] Suggest missing format attributes (PR #166738)

Vladimir Vuksanovic via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 17 07:36:05 PST 2025


================
@@ -7061,6 +7140,16 @@ bool Sema::CheckFormatArguments(ArrayRef<const Expr *> Args,
       SourceMgr.isInSystemMacro(FormatLoc))
     return false;
 
+  const LangOptions &LO = getLangOpts();
+  if (CallerParamIdx && (LO.GNUMode || LO.C23 || LO.CPlusPlus11))
----------------
vvuksanovic wrote:

Right, the user can figure out a way to write the attribute in a suitable way. I have changed the diagnostic message to include the attribute parameters as well like:
```
diagnostic behavior may be improved by adding the 'format(printf, X, Y)' attribute to the declaration of 'foo'
```
so even if there is no fixit, the full suggested attribute is still shown.

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


More information about the cfe-commits mailing list