is used without -Wformat.
* c-common.h (warn_format_zero_length): Declare extern.
* c-decl.c (warn_options): Add "format-zero-length".
* c-format.c (warn_format_zero_length): Declare.
(set_Wformat): Set warn_format_zero_length for -Wformat.
(check_format_info): Only warn about zero-length formats if
warn_format_zero_length is true. Include the format type
name in the warning message.
* doc/invoke.texi: Document -Wformat-zero-length.
* testsuite/gcc.dg/format/zero-length-1.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53592
138bc75d-0d04-0410-961f-
82ee72b054a4
+2002-05-18 Jason Thorpe <thorpej@wasabisystems.com>
+
+ * c-common.c (c_common_post_options): Warn if -Wformat-zero-length
+ is used without -Wformat.
+ * c-common.h (warn_format_zero_length): Declare extern.
+ * c-decl.c (warn_options): Add "format-zero-length".
+ * c-format.c (warn_format_zero_length): Declare.
+ (set_Wformat): Set warn_format_zero_length for -Wformat.
+ (check_format_info): Only warn about zero-length formats if
+ warn_format_zero_length is true. Include the format type
+ name in the warning message.
+ * doc/invoke.texi: Document -Wformat-zero-length.
+ * testsuite/gcc.dg/format/zero-length-1.c: New test.
+
2002-05-18 Kazu Hirata <kazu@cs.umass.edu>
* timevar.c: Fix formatting.
warning ("-Wformat-y2k ignored without -Wformat");
if (warn_format_extra_args && !warn_format)
warning ("-Wformat-extra-args ignored without -Wformat");
+ if (warn_format_zero_length && !warn_format)
+ warning ("-Wformat-zero-length ignored without -Wformat");
if (warn_format_nonliteral && !warn_format)
warning ("-Wformat-nonliteral ignored without -Wformat");
if (warn_format_security && !warn_format)
extern int warn_format_extra_args;
+/* Warn about zero-length formats. */
+
+extern int warn_format_zero_length;
+
/* Warn about non-literal format arguments. */
extern int warn_format_nonliteral;
{ "div-by-zero", &warn_div_by_zero },
{ "float-equal", &warn_float_equal },
{ "format-extra-args", &warn_format_extra_args },
+ { "format-zero-length", &warn_format_zero_length },
{ "format-nonliteral", &warn_format_nonliteral },
{ "format-security", &warn_format_security },
{ "format-y2k", &warn_format_y2k },
int warn_format_extra_args;
+/* Warn about zero-length formats. */
+
+int warn_format_zero_length;
+
/* Warn about non-literal format arguments. */
int warn_format_nonliteral;
warn_format = setting;
warn_format_y2k = setting;
warn_format_extra_args = setting;
+ warn_format_zero_length = setting;
if (setting != 1)
{
warn_format_nonliteral = setting;
&& res.number_other == 0 && warn_format_extra_args)
status_warning (status, "unused arguments in $-style format");
if (res.number_empty > 0 && res.number_non_literal == 0
- && res.number_other == 0)
- status_warning (status, "zero-length format string");
+ && res.number_other == 0 && warn_format_zero_length)
+ status_warning (status, "zero-length %s format string",
+ format_types[info->format_type].name);
if (res.number_wide > 0)
status_warning (status, "format is a wide character string");
@option{-Wformat} is included in @option{-Wall}. For more control over some
aspects of format checking, the options @option{-Wno-format-y2k},
-@option{-Wno-format-extra-args}, @option{-Wformat-nonliteral},
-@option{-Wformat-security} and @option{-Wformat=2} are available, but are
-not included in @option{-Wall}.
+@option{-Wno-format-extra-args}, @option{-Wno-format-zero-length},
+@option{-Wformat-nonliteral}, @option{-Wformat-security}, and
+@option{-Wformat=2} are available, but are not included in @option{-Wall}.
@item -Wno-format-y2k
@opindex Wno-format-y2k
warning if the unused arguments are all pointers, since the Single
Unix Specification says that such unused arguments are allowed.
+@item -Wno-format-zero-length
+@opindex Wno-format-zero-length
+If @option{-Wformat} is specified, do not warn about zero-length formats.
+The C standard specifies that zero-length formats are allowed.
+
@item -Wformat-nonliteral
@opindex Wformat-nonliteral
If @option{-Wformat} is specified, also warn if the format string is not a
--- /dev/null
+/* Test the -Wno-format-zero-length option, which suppresses warnings
+ about zero-length formats. */
+/* Origin: Jason Thorpe <thorpej@wasabisystems.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wno-format-zero-length" } */
+
+#include "format.h"
+
+void
+foo (void)
+{
+ /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134). */
+ /* Zero-length format strings are allowed. */
+ printf ("");
+}