Skip to content

Clang flag -Wmissing-format-attribute doesn't catch missing attributes #60718

@jstengleingithub

Description

@jstengleingithub

GCC has a valuable flag -Wmissing-format-attribute which shows functions missing a format attribute. While Clang supports this flag, it currently doesn't do anything.
Code:

#include <stddef.h> #include <string.h> #include <stdarg.h> #include <stdio.h> void safe_snprintf(char *outstring, const size_t length, const char *format, ... /* args */); void safe_snprintf(char *outstring, const size_t length, const char *format, ... /* args */) { va_list args; va_start(args, format); if ((outstring != NULL) && (length > 0)) { vsnprintf(outstring, length, format, args); outstring[length - 1] = 0; } va_end(args); }

GCC warning:

$ gcc -c -Wmissing-format-attribute test.c test.c: In function 'safe_snprintf': test.c:18:9: warning: function 'safe_snprintf' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]  vsnprintf(outstring, length, format, args);  ^~~~~~~~~ $ gcc --version gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1)

Clang supports the flag but finds no issue:

$ ./clang -Wmissing-format-attribute -c ../../test.c (no warning) $ ./clang --version Clang version 17.0.0 6ac13a798adae9a40023200dcaa6ed2e9fd9033a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions