On 11/11/2016 06:30 PM, David Malcolm wrote:
This patch implements fix-it hints to -Wmissing-braces, showing where to
add braces.
For example:
$ cat test.c
int arr_2_3_2[2][3][2] =
{ 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11};
$ ./xgcc -B. -c test.c -Wall -fdiagnostics-generate-patch
test.c:2:3: warning: missing braces around initializer [-Wmissing-braces]
{ 0, 1, 2, 3, 4, 5,
^
{
{ } { } { }
}
6, 7, 8, 9, 10, 11};
{
{ } { } { }
}
--- test.c
+++ test.c
@@ -1,3 +1,3 @@
int arr_2_3_2[2][3][2] =
- { 0, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 11};
+ { {{0, 1}, {2, 3}, {4, 5}},
+ {{6, 7}, {8, 9}, {10, 11}}};
Successfully bootstrapped®rtested on x86_64-pc-linux-gnu; adds
29 PASS results to gcc.sum.
OK for trunk?
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.
I'm a bit unsure about how useful this is in practice. But OK.
jeff