On 8/5/19 11:51 AM, Martin Sebor wrote:
> When the argument to a directive with a length modifier like %lu
> in a call to a GCC diagnostic function such as warning()) is not
> of the right integer type, GCC suggests to replace the length
> modifier in the directive with 'w'.  For instance:
> 
>   warning: format ‘%lu’ expects argument of type ‘long unsigned int’,
> but argument 2 has type ‘int’ [-Wformat=]
>    f ("%lu", 0);
>        ~~^
>        %wu
> 
> To issue the right hint (i.e., %u in the message above) the attached
> patch introduces a new format_lengths enumerator to represent the 'w'
> modifier.
> 
> Tested on x86_64-linux.
> 
> Martin
> 
> gcc-80619.diff
> 
> PR c/80619 - bad fix-it hint for GCC %lu directive with int argument: %wu
> 
> gcc/c-family/ChangeLog:
> 
>       PR c/80619
>       * c-format.c (printf_length_specs): Set FMT_LEN_w for "w".
>       (asm_fprintf_length_spec): Same.
>       * c-format.h (format_lengths): Add FMT_LEN_w.
> 
> gcc/testsuite/ChangeLog:
> 
>       PR c/80619
>       * gcc.dg/format/pr80619.c: New test.
OK
jeff

Reply via email to