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

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 10 09:55:48 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))
+    CheckMissingFormatAttributes(this, Type, format_idx, firstDataArg, Args,
+                                 APK, *CallerParamIdx, Loc);
----------------
apple-fcloutier wrote:

Sure, what about the other format families? I haven't built your change to play with it, but my suspicion is that if you enable `-Wformat-nonliteral` and `-Wmissing-format-attribute`, then you usually will trip both:

```
#include <stdarg.h>

__attribute__((format(printf, 1, 0))) void foo(const char *, va_list);

void bar(const char *fmt, ...) {
	va_list ap;
	va_start(ap, fmt);
	foo(fmt, ap); // <---- 
	va_end(ap);
}
```

If that's not the case (or actually, even if that's the case), I think you should have a test that shows we emit only one or the other.

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


More information about the cfe-commits mailing list