aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/format/miss-7.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/format/miss-7.c')
-rw-r--r--gcc/testsuite/gcc.dg/format/miss-7.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/format/miss-7.c b/gcc/testsuite/gcc.dg/format/miss-7.c
new file mode 100644
index 00000000000..828b781e0e6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/miss-7.c
@@ -0,0 +1,36 @@
+/* PR77336 - -Wsuggest-attribute=format warning overly simplistic */
+/* { dg-do compile } */
+/* { dg-options "-Wsuggest-attribute=format" } */
+
+#include "format.h"
+
+const char format[] = "%i";
+
+void foo (char *d, unsigned n, va_list va)
+{
+ (void)&n;
+
+ /* The following calls don't imply that the enclosing function is
+ a candiate for the format attribute because it uses a string
+ constant as the format. */
+ vsnprintf (d, n, "%i", va);
+
+ vsnprintf (d, n, format, va);
+
+ /* In theory this should not trigger the warning either but GCC
+ doesn't treat the local static constant the same way as the
+ global and issues a false positive.
+ const char fmt[] = "%i";
+ vsnprintf (d, n, fmt, va);
+ */
+}
+
+void bar (char *d, unsigned n, const char *f, va_list va)
+{
+ (void)&n;
+
+ /* The following call suggests that the enclosing function might
+ be a candiate for the format attribute because it doesn't use
+ a string literal as the format. */
+ vsnprintf (d, n, f, va); /* { dg-warning "function .bar. might be a candidate for .gnu_printf. format attribute" } */
+}