This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
printf checking X/Open extensions patch
- To: gcc-patches at gcc dot gnu dot org
- Subject: printf checking X/Open extensions patch
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Date: Sat, 5 Aug 2000 09:33:53 +0100 (BST)
This patch adds support for the X/Open ' format flag, and adds a
pedantic warning for use of $ formats. ($ formats need more work; use
of $ and non-$ formats together in a format string is undefined
according to X/Open and should be diagnosed, and GCC doesn't handle
the use of $ specifications for width and precision.)
(%F is included in this patch as a format which can be used with ' on
the expectation that its omission from the list in the latest Austin
Group draft is a bug; a bug report has been submitted to the Austin
Group. The ' flag is already in the Single Unix Specification; the
Austin Group draft aligns with C99 but fails to add %'F.)
Since X/Open says %C is equivalent to %lc, this patch also adjusts %C
to expect wint_t.
Bootstrapped with no regressions on i686-pc-linux-gnu. OK to commit?
2000-08-05 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.c (print_char_table): Add entries for the X/Open '
format flag (print decimals with locale's thousands grouping
character). Make %C expect wint_t.
(check_format_info): If pedantic, warn when the %n$ operand
number form is used. Allow for the ' flag; warn about it if
pedantic.
--- c-common.c Fri Aug 4 23:01:34 2000
+++ c-common.c.new Sat Aug 5 00:35:18 2000
@@ -1233,14 +1233,15 @@ typedef struct {
} format_char_info;
static format_char_info print_char_table[] = {
- { "di", 0, T_I, T_I, T_I, T_L, T_LL, T_LL, T_ST, T_PD, T_IM, "-wp0 +" },
+ { "di", 0, T_I, T_I, T_I, T_L, T_LL, T_LL, T_ST, T_PD, T_IM, "-wp0 +'" },
{ "oxX", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, T_PD, T_UIM, "-wp0#" },
- { "u", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, T_PD, T_UIM, "-wp0" },
+ { "u", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, T_PD, T_UIM, "-wp0'" },
/* A GNU extension. */
{ "m", 0, T_V, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
- { "fFeEgGaA", 0, T_D, NULL, NULL, T_D, NULL, T_LD, NULL, NULL, NULL, "-wp0 +#" },
+ { "fFgG", 0, T_D, NULL, NULL, T_D, NULL, T_LD, NULL, NULL, NULL, "-wp0 +#'" },
+ { "eEaA", 0, T_D, NULL, NULL, T_D, NULL, T_LD, NULL, NULL, NULL, "-wp0 +#" },
{ "c", 0, T_I, NULL, NULL, T_WI, NULL, NULL, NULL, NULL, NULL, "-w" },
- { "C", 0, T_W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
+ { "C", 0, T_WI, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
{ "s", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, NULL, NULL, "-wp" },
{ "S", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
{ "p", 1, T_V, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
@@ -1699,6 +1700,9 @@ check_format_info (info, params)
{
int opnum = atoi (format_chars);
+ if (pedantic)
+ warning ("ANSI C does not support printf %%n$");
+
params = first_fillin_param;
format_chars = p + 1;
has_operand_number = 1;
@@ -1714,7 +1718,7 @@ check_format_info (info, params)
}
}
- while (*format_chars != 0 && index (" +#0-", *format_chars) != 0)
+ while (*format_chars != 0 && index (" +#0-'", *format_chars) != 0)
{
if (index (flag_chars, *format_chars) != 0)
warning ("repeated `%c' flag in format", *format_chars++);
@@ -1735,6 +1739,8 @@ check_format_info (info, params)
if (index (flag_chars, '0') != 0
&& index (flag_chars, '-') != 0)
warning ("use of both `0' and `-' flags in format");
+ if (index (flag_chars, '\'') && pedantic)
+ warning ("ANSI C does not support the `'' format flag");
if (*format_chars == '*')
{
wide = TRUE;
--
Joseph S. Myers
jsm28@cam.ac.uk