-Wformat
Ulrich Drepper
drepper@cygnus.com
Fri Jan 28 21:11:00 GMT 2000
The appended patch changes -Wformat to optionally take a parameter and
set the flag appropriately. The non-constant printf string warning is
only emitted if the flag value is > 1 (default is 1). This was
discussed when the patch which makes this one necessary went in. I
think Mike Meissner proposed it this way.
--
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Red Hat `--' drepper at redhat.com `------------------------
2000-01-28 Ulrich Drepper <drepper@redhat.com>
* c-decl.c (c_decode_option): Accept optional numeric argument to
-Wformat and set warn_format.
* c-common.c: Don't emit warning about non-constant printf format
string unless warn_format > 1.
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.c,v
retrieving revision 1.89
diff -u -u -w -r1.89 c-common.c
--- c-common.c 2000/01/25 17:13:13 1.89
+++ c-common.c 2000/01/29 04:34:40
@@ -1529,7 +1529,7 @@
/* Functions taking a va_list normally pass a non-literal format
string. These functions typically are declared with
first_arg_num == 0, so avoid warning in those cases. */
- if (info->first_arg_num != 0)
+ if (info->first_arg_num != 0 && warn_format > 1)
warning ("format not a string literal, argument types not checked");
return;
}
@@ -1541,7 +1541,7 @@
/* Functions taking a va_list normally pass a non-literal format
string. These functions typically are declared with
first_arg_num == 0, so avoid warning in those cases. */
- if (info->first_arg_num != 0)
+ if (info->first_arg_num != 0 && warn_format > 1)
warning ("format not a string literal, argument types not checked");
return;
}
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-decl.c,v
retrieving revision 1.94
diff -u -u -w -r1.94 c-decl.c
--- c-decl.c 2000/01/25 17:13:13 1.94
+++ c-decl.c 2000/01/29 04:35:02
@@ -675,6 +677,8 @@
warn_traditional = 1;
else if (!strcmp (p, "-Wno-traditional"))
warn_traditional = 0;
+ else if (!strncmp (p, "-Wformat=", 9))
+ warn_format = atol (p + 9);
else if (!strcmp (p, "-Wformat"))
warn_format = 1;
else if (!strcmp (p, "-Wno-format"))
More information about the Gcc-patches
mailing list