FMT_FLAG_SCANF_A_KLUDGE = 2,
/* A % during parsing a specifier is allowed to be a modified % rather
that indicating the format is broken and we are out-of-sync. */
- FMT_FLAG_FANCY_PERCENT_OK = 4
+ FMT_FLAG_FANCY_PERCENT_OK = 4,
+ /* With $ operand numbers, it is OK to reference the same argument more
+ than once. */
+ FMT_FLAG_DOLLAR_MULTIPLE = 8
/* Not included here: details of whether width or precision may occur
(controlled by width_char and precision_char); details of whether
'*' can be used for these (width_type and precision_type); details
{
{ "printf", printf_length_specs, print_char_table, " +#0-'I", NULL,
printf_flag_specs, printf_flag_pairs,
- FMT_FLAG_ARG_CONVERT, 'w', 'p', 0, 'L',
+ FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE, 'w', 'p', 0, 'L',
&integer_type_node, &integer_type_node
},
{ "scanf", scanf_length_specs, scan_char_table, "*'I", NULL,
static void init_dollar_format_checking PARAMS ((int, tree));
static int maybe_read_dollar_number PARAMS ((int *, const char **, int,
- tree, tree *));
+ tree, tree *,
+ const format_kind_info *));
static void finish_dollar_format_checking PARAMS ((int *, format_check_results *));
static const format_flag_spec *get_flag_spec PARAMS ((const format_flag_spec *,
a $ format is found, *FORMAT is updated to point just after it. */
static int
-maybe_read_dollar_number (status, format, dollar_needed, params, param_ptr)
+maybe_read_dollar_number (status, format, dollar_needed, params, param_ptr,
+ fki)
int *status;
const char **format;
int dollar_needed;
tree params;
tree *param_ptr;
+ const format_kind_info *fki;
{
int argnum;
int overflow_flag;
nalloc - dollar_arguments_alloc);
dollar_arguments_alloc = nalloc;
}
- dollar_arguments_used[argnum - 1] = 1;
+ if (!(fki->flags & FMT_FLAG_DOLLAR_MULTIPLE)
+ && dollar_arguments_used[argnum - 1] == 1)
+ {
+ dollar_arguments_used[argnum - 1] = 2;
+ status_warning (status,
+ "format argument %d used more than once in %s format",
+ argnum, fki->name);
+ }
+ else
+ dollar_arguments_used[argnum - 1] = 1;
if (dollar_first_arg_num)
{
int i;
int opnum;
opnum = maybe_read_dollar_number (status, &format_chars, 0,
first_fillin_param,
- &main_arg_params);
+ &main_arg_params, fki);
if (opnum == -1)
return;
else if (opnum > 0)
opnum = maybe_read_dollar_number (status, &format_chars,
has_operand_number == 1,
first_fillin_param,
- ¶ms);
+ ¶ms, fki);
if (opnum == -1)
return;
else if (opnum > 0)
opnum = maybe_read_dollar_number (status, &format_chars,
has_operand_number == 1,
first_fillin_param,
- ¶ms);
+ ¶ms, fki);
if (opnum == -1)
return;
else if (opnum > 0)
/* Test for X/Open format extensions, as found in the
Single Unix Specification and in Austin Group draft 4, subject to some
- Aardvark problem reports submitted.
+ Aardvark problem reports approved as changes.
*/
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
*/
scanf ("%aS", fp);
/* The printf flag character ' is an X/Open extension. */
- /* Allowing %'F here presumes acceptance of the corresponding Aardvark
- report.
- */
printf ("%'d%'i%'u%'f%'F%'g%'G", i, i, u, d, d, d, d);
printf ("%'o", u); /* { dg-warning "flag" "bad use of ' flag" } */
printf ("%'x", u); /* { dg-warning "flag" "bad use of ' flag" } */
printf ("%'p", p); /* { dg-warning "flag" "bad use of ' flag" } */
printf ("%'n", n); /* { dg-warning "flag" "bad use of ' flag" } */
/* The use of operand number $ formats is an X/Open extension. */
- /* Banning gaps in the arguments used with scanf, and not objecting to
- multiple use of an argument with scanf, presumes acceptance of the
- corresponding Aardvark reports.
+ /* Banning gaps in the arguments used with scanf was covered in Aardvark
+ report XSHd4 ERN 164, which was rejected, but implementation without
+ such a ban still isn't possible within ISO C.
*/
scanf ("%1$d", ip);
printf ("%1$d", i);
printf ("%3$d%1$d", i, i, i); /* { dg-warning "before used" "unused $ operand" } */
printf ("%2$d%1$d", i, i, i); /* { dg-warning "unused" "unused $ operand" } */
vprintf ("%3$d%1$d", va); /* { dg-warning "before used" "unused $ operand" } */
- scanf ("%1$*d%1$d", ip); /* { dg-warning "operand" "operand number with suppression" } */
+ scanf ("%2$*d%1$d", ip, ip); /* { dg-warning "operand" "operand number with suppression" } */
+ printf ("%1$d%1$d", i);
+ scanf ("%1$d%1$d", ip); /* { dg-warning "more than once" "multiple use of scanf argument" } */
}