attributes to functions with no parameter to which to add them.
testsuite:
* gcc.dg/format-miss-2.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38163
138bc75d-0d04-0410-961f-
82ee72b054a4
+2000-12-09 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * c-common.c (check_function_format): Don't suggest adding format
+ attributes to functions with no parameter to which to add them.
+
2000-12-09 Nick Clifton <nickc@redhat.com>
* config/arm/arm.c (arm_expand_prologue): Mark the generated
&& info2->format_type == info->format_type)
break;
if (info2 == NULL)
- warning ("function might be possible candidate for `%s' format attribute",
- format_types[info->format_type].name);
+ {
+ /* Check if the current function has a parameter to which
+ the format attribute could be attached; if not, it
+ can't be a candidate for a format attribute, despite
+ the vprintf-like or vscanf-like call. */
+ tree args;
+ for (args = DECL_ARGUMENTS (current_function_decl);
+ args != 0;
+ args = TREE_CHAIN (args))
+ {
+ if (TREE_CODE (TREE_TYPE (args)) == POINTER_TYPE
+ && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (args)))
+ == char_type_node))
+ break;
+ }
+ if (args != 0)
+ warning ("function might be possible candidate for `%s' format attribute",
+ format_types[info->format_type].name);
+ }
}
break;
}
+2000-12-09 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * gcc.dg/format-miss-2.c: New test.
+
2000-12-09 Neil Booth <neilb@earthling.net>
* gcc.dg/cpp/lineflags.c: New tests.
--- /dev/null
+/* Test for warnings for missing format attributes. Don't warn if no
+ relevant parameters for a format attribute; see c/1017. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat -Wmissing-format-attribute" } */
+
+#include <stdarg.h>
+
+extern int vprintf (const char *restrict, va_list);
+
+void
+foo (int i, ...)
+{
+ va_list ap;
+ va_start (ap, i);
+ vprintf ("Foo %s bar %s", ap); /* { dg-bogus "candidate" "bogus printf attribute warning" } */
+ va_end (ap);
+}