Fix suggestions for non-trivial Wformat type cases (PR c/72858)
commit004340323a9633787fd723dcb658bfee8d44cac2
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 Sep 2016 16:01:02 +0000 (12 16:01 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 Sep 2016 16:01:02 +0000 (12 16:01 +0000)
tree6a245d08d2a9d5e8e29c972d3106de14df2314a6
parent2552de7b2250363c39f03638910a16798d40e75d
Fix suggestions for non-trivial Wformat type cases (PR c/72858)

gcc/c-family/ChangeLog:
PR c/72858
* c-format.c (argument_parser::check_argument_type): Add params
"type_start" and "conversion_char".  Use the former to generate
offset_to_type_start and pass it and conversion_char to
check_format_types.
(check_format_info_main): Capture the start of the type
information as "type_start", and pass it an format_char
to arg_parser.check_argument_type.
(check_format_types): Provide an example in the leading comment.
Add params "offset_to_type_start" and "conversion_char"; pass
them to format_type_warning calls.
(test_get_modifier_for_format_len): Likewise.
(matching_type_p): New function.
(get_format_for_type): Add param "conversion_char" and move
implementation into...
(get_format_for_type_1): ...new function, called twice.
Use new function matching_type_p rather than checking for
TYPE_CANONICAL equality.
(get_corrected_substring): New function.
(format_type_warning): Provide an example in the leading comment.
Add params "offset_to_type_start" and "conversion_char".  Replace
call to get_format_for_type with call to get_corrected_substring
and move rejection of hints for widths/precisions there.
(assert_format_for_type_streq): Add param "conversion_char".
(ASSERT_FORMAT_FOR_TYPE_STREQ): Add param CONVERSION_CHAR.
(test_get_format_for_type_printf): Add conversion chars to the
tests, adding coverage for various combinations of integer
vs double conversions, and for preserving octal and hexadecimal
conversions.
(test_get_format_for_type_scanf): Add conversion chars to the
tests.

gcc/testsuite/ChangeLog:
PR c/72858
* gcc.dg/format/diagnostic-ranges.c: Update expected suggestions
to preserve conversion chars, and to preserve prefix information.
* gcc.dg/format/pr72858.c: New test case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240095 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/c-family/ChangeLog
gcc/c-family/c-format.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/diagnostic-ranges.c
gcc/testsuite/gcc.dg/format/pr72858.c [new file with mode: 0644]