C FE: implement fix-it hint for -Wmissing-braces
commit8ccda24ac9e334cb5fbe18a87ed88cdb9c974107
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Jan 2017 17:40:59 +0000 (4 17:40 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Jan 2017 17:40:59 +0000 (4 17:40 +0000)
tree881a273cbb54d8222e066d9f714a5334e21e14fb
parenta10f19a61f94d3c07978046e562e0941fcd99cc9
C FE: implement fix-it hint for -Wmissing-braces

gcc/c/ChangeLog:
* c-parser.c (c_parser_declaration_or_fndef): Create a
rich_location at init_loc and parse it to start_init.
(last_init_list_comma): New global.
(c_parser_braced_init): Update last_init_list_comma when parsing
commas.  Pass it to pop_init_level.  Pass location of closing
brace to pop_init_level.
(c_parser_postfix_expression_after_paren_type): Create a
rich_location at type_loc and parse it to start_init.
(c_parser_omp_declare_reduction): Likewise for loc.
* c-tree.h (start_init): Add rich_location * param.
(pop_init_level): Add location_t param.
* c-typeck.c (struct initializer_stack): Add field
"missing_brace_richloc".
(start_init): Add richloc param, use it to initialize
the stack node's missing_brace_richloc.
(last_init_list_comma): New decl.
(finish_implicit_inits): Pass last_init_list_comma to
pop_init_level.
(push_init_level): When finding missing open braces, add fix-it
hints to the richloc.
(pop_init_level): Add "insert_before" param and pass it
when calling pop_init_level.  Add fixits about missing
close braces to any richloc.  Use the richloc for the
-Wmissing-braces warning.
(set_designator): Pass last_init_list_comma to pop_init_level.
(process_init_element): Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/Wmissing-braces-fixits.c: New test case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@244061 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/c/c-tree.h
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wmissing-braces-fixits.c [new file with mode: 0644]