aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2000-12-01 22:43:33 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2000-12-01 22:43:33 +0000
commit4d80892796677b2beaf9d47d80e337b315395582 (patch)
treebdb5953541ec233f2de9b035d07dd0cc7f8757c2 /gcc/c-common.c
parente78f4a977a1f0f802035fd473d64659d4f48a8ab (diff)
downloadgcc-4d80892796677b2beaf9d47d80e337b315395582.zip
gcc-4d80892796677b2beaf9d47d80e337b315395582.tar.gz
gcc-4d80892796677b2beaf9d47d80e337b315395582.tar.bz2
c-common.c (warn_format, [...]): Define.
* c-common.c (warn_format, warn_format_y2k, warn_format_extra_args, warn_format_nonliteral): Define. (check_format_info): Check warn_format_nonliteral and warn_format_extra_args. (check_format_info_main): Check warn_format_y2k. (set_Wformat): New function. * c-common.h (warn_format_y2k, warn_format_extra_args, warn_format_nonliteral, set_Wformat): Declare. * c-decl.c (warn_format): Remove definition. (c_decode_option): Handle -Wformat-nonliteral, -Wno-format-extra-args and -Wno-format-y2k, and negated versions. Use set_Wformat. * invoke.texi: Document these new options and -Wformat=2. * toplev.c (documented_lang_options): Add these new options. cp: * decl2.c (warn_format): Remove definition. (lang_decode_option): Handle -Wformat-nonliteral, -Wno-format-extra-args and -Wno-format-y2k. Use set_Wformat. testsuite: * gcc.dg/format-no-exargs-1.c, gcc.dg/format-no-y2k-1.c, gcc.dg/format-nonlit-1.c, gcc.dg/format-nonlit-2.c: New tests. From-SVN: r37933
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c66
1 files changed, 48 insertions, 18 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index c4fd463..e07a7d3 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -173,6 +173,22 @@ int flag_no_nonansi_builtin;
const char *flag_dump_translation_unit;
+/* Warn about *printf or *scanf format/argument anomalies. */
+
+int warn_format;
+
+/* Warn about Y2K problems with strftime formats. */
+
+int warn_format_y2k;
+
+/* Warn about excess arguments to formats. */
+
+int warn_format_extra_args;
+
+/* Warn about non-literal format arguments. */
+
+int warn_format_nonliteral;
+
/* Nonzero means warn about possible violations of sequence point rules. */
int warn_sequence_point;
@@ -2321,7 +2337,7 @@ check_format_info (status, info, params)
/* 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 && warn_format > 1)
+ if (info->first_arg_num != 0 && warn_format_nonliteral)
status_warning (status, "format not a string literal, argument types not checked");
}
@@ -2333,10 +2349,10 @@ check_format_info (status, info, params)
If the format is an empty string, this should be counted similarly to the
case of extra format arguments. */
if (res.number_extra_args > 0 && res.number_non_literal == 0
- && res.number_other == 0)
+ && res.number_other == 0 && warn_format_extra_args)
status_warning (status, "too many arguments for format");
if (res.number_dollar_extra_args > 0 && res.number_non_literal == 0
- && res.number_other == 0)
+ && 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)
@@ -2991,23 +3007,24 @@ check_format_info_main (status, res, info, format_chars, format_length,
}
/* Give Y2K warnings. */
- {
- int y2k_level = 0;
- if (strchr (fci->flags2, '4') != 0)
- if (strchr (flag_chars, 'E') != 0)
+ if (warn_format_y2k)
+ {
+ int y2k_level = 0;
+ if (strchr (fci->flags2, '4') != 0)
+ if (strchr (flag_chars, 'E') != 0)
+ y2k_level = 3;
+ else
+ y2k_level = 2;
+ else if (strchr (fci->flags2, '3') != 0)
y2k_level = 3;
- else
+ else if (strchr (fci->flags2, '2') != 0)
y2k_level = 2;
- else if (strchr (fci->flags2, '3') != 0)
- y2k_level = 3;
- else if (strchr (fci->flags2, '2') != 0)
- y2k_level = 2;
- if (y2k_level == 3)
- status_warning (status, "`%%%c' yields only last 2 digits of year in some locales",
- format_char);
- else if (y2k_level == 2)
- status_warning (status, "`%%%c' yields only last 2 digits of year", format_char);
- }
+ if (y2k_level == 3)
+ status_warning (status, "`%%%c' yields only last 2 digits of year in some locales",
+ format_char);
+ else if (y2k_level == 2)
+ status_warning (status, "`%%%c' yields only last 2 digits of year", format_char);
+ }
if (strchr (fci->flags2, '[') != 0)
{
@@ -3325,6 +3342,19 @@ check_format_types (status, types)
}
}
}
+
+/* Set format warning options according to a -Wformat=n option. */
+
+void
+set_Wformat (setting)
+ int setting;
+{
+ warn_format = setting;
+ warn_format_y2k = setting;
+ warn_format_extra_args = setting;
+ if (setting != 1)
+ warn_format_nonliteral = setting;
+}
/* Print a warning if a constant expression had overflow in folding.
Invoke this function on every expression that the language