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

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 10 09:47:21 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))
----------------
apple-fcloutier wrote:

There are portable ways to annotate your functions, it's just that you can't offer them as fixits for a variety of reasons (for instance, create a macro that adds the format attribute based on a `__has_attribute` test); in fact, even when a language-defined syntax is available, it might not be the preferred way to add the attribute in any given project.

But even then, I disagree that the only value (or even the main value) of _any_ diagnostic is the fixit. Clang doesn't only diagnose situations that it knows how to fix. For a codebase that _truly_ can't do anything about missing format attributes, the solution is to not take the intentional step of enabling the diagnostic.

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


More information about the cfe-commits mailing list