1 /* PR77336 - -Wsuggest-attribute=format warning overly simplistic */
2 /* { dg-do compile } */
3 /* { dg-options "-Wsuggest-attribute=format" } */
4
5 #include "format.h"
6
7 const char format[] = "%i";
8
foo(char * d,unsigned n,va_list va)9 void foo (char *d, unsigned n, va_list va)
10 {
11 (void)&n;
12
13 /* The following calls don't imply that the enclosing function is
14 a candiate for the format attribute because it uses a string
15 constant as the format. */
16 vsnprintf (d, n, "%i", va);
17
18 vsnprintf (d, n, format, va);
19
20 /* In theory this should not trigger the warning either but GCC
21 doesn't treat the local static constant the same way as the
22 global and issues a false positive.
23 const char fmt[] = "%i";
24 vsnprintf (d, n, fmt, va);
25 */
26 }
27
bar(char * d,unsigned n,const char * f,va_list va)28 void bar (char *d, unsigned n, const char *f, va_list va)
29 {
30 (void)&n;
31
32 /* The following call suggests that the enclosing function might
33 be a candiate for the format attribute because it doesn't use
34 a string literal as the format. */
35 vsnprintf (d, n, f, va); /* { dg-warning "function .bar. might be a candidate for .gnu_printf. format attribute" } */
36 }
37