llvm-project/clang/test/Sema/attr-format_arg.c
Michael Kruse f18adbb3cb [Sema] Consider all format_arg attributes.
If a function has multiple format_arg attributes, clang only considers
the first it finds (because AttributeLists are in reverse order, not
necessarily the textually first) and ignores all others.

Loop over all FormatArgAttr to print warnings for all declared
format_arg attributes.

For instance, libintl's ngettext (select plural or singular version of
format string) has two __format_arg__ attributes.

Differential Revision: https://reviews.llvm.org/D48734

llvm-svn: 336239
2018-07-04 01:37:11 +00:00

31 lines
855 B
C

// RUN: %clang_cc1 -fsyntax-only -verify %s
int printf(const char *, ...);
const char* f(const char *s) __attribute__((format_arg(1)));
const char *h(const char *msg1, const char *msg2)
__attribute__((__format_arg__(1))) __attribute__((__format_arg__(2)));
void g(const char *s) {
printf("%d", 123);
printf("%d %d", 123); // expected-warning{{more '%' conversions than data arguments}}
printf(f("%d"), 123);
printf(f("%d %d"), 123); // expected-warning{{more '%' conversions than data arguments}}
printf(h(
"", // expected-warning {{format string is empty}}
"" // expected-warning {{format string is empty}}
), 123);
printf(h(
"%d",
"" // expected-warning {{format string is empty}}
), 123);
printf(h(
"", // expected-warning {{format string is empty}}
"%d"
), 123);
printf(h("%d", "%d"), 123);
}