[clang] [Sema] Suggest missing format attributes (PR #166738)
Vladimir Vuksanovic via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 10 09:40:34 PST 2025
================
@@ -3478,6 +3478,10 @@ def err_format_attribute_result_not : Error<"function does not return %0">;
def err_format_attribute_implicit_this_format_string : Error<
"format attribute cannot specify the implicit this argument as the format "
"string">;
+def warn_missing_format_attribute : Warning<
+ "diagnostic behavior may be improved by adding the '%0' format "
+ "attribute to the declaration of %1">,
+ InGroup<DiagGroup<"missing-format-attribute">>, DefaultIgnore;
----------------
vvuksanovic wrote:
In GCC -Wmissing-format-attribute or -Wsuggest-attribute=format is an off-by-default warning unrelated to all other -Wformat* options. I think it makes sense to group this in -Wformat-nonliteral or -Wformat, though it is more of a suggestion to improve diagnostics than an actual warning like -Wformat-nonliteral.
> In all cases, -Wformat-nonliteral always hitting when -Wmissing-format-attribute does is an overlook that we should address.
I mentioned in another comment, there is an exception with `strftime` calls. It does not trigger -Wformat-nonliteral since it always has one argument, but it still makes sense to add the attribute to the caller. Note that GCC actually doesn't emit -Wmissing-format-attribute in that case because the callee is not variadic.
https://github.com/llvm/llvm-project/pull/166738
More information about the cfe-commits
mailing list