diff options
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 2 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 2 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 21 |
4 files changed, 32 insertions, 3 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index cd9f230..08fc250 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,13 @@ +2016-06-13 David Malcolm <dmalcolm@redhat.com> + + * c-parser.c (c_parser_initelt): Provide location of name for new + location_t param of set_init_label. + * c-tree.h (set_init_label): Add location_t param. + * c-typeck.c (set_init_index): Add "fieldname_loc" location_t + param and use it when issuing error messages about unrecognized + field names. Attempt to provide a fixit hint if appropriate, + otherwise update the error message to provide the type name. + 2016-06-10 Thomas Schwinge <thomas@codesourcery.com> PR c/71381 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 94078a9..ff32479 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -4397,6 +4397,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) /* Old-style structure member designator. */ set_init_label (c_parser_peek_token (parser)->location, c_parser_peek_token (parser)->value, + c_parser_peek_token (parser)->location, braced_init_obstack); /* Use the colon as the error location. */ pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic, @@ -4426,6 +4427,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) if (c_parser_next_token_is (parser, CPP_NAME)) { set_init_label (des_loc, c_parser_peek_token (parser)->value, + c_parser_peek_token (parser)->location, braced_init_obstack); c_parser_consume_token (parser); } diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index b4374e3..8f10a13 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -639,7 +639,7 @@ extern void finish_implicit_inits (location_t, struct obstack *); extern void push_init_level (location_t, int, struct obstack *); extern struct c_expr pop_init_level (location_t, int, struct obstack *); extern void set_init_index (location_t, tree, tree, struct obstack *); -extern void set_init_label (location_t, tree, struct obstack *); +extern void set_init_label (location_t, tree, location_t, struct obstack *); extern void process_init_element (location_t, struct c_expr, bool, struct obstack *); extern tree build_compound_literal (location_t, tree, tree, bool); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a681d76..ea04d5e 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -8211,7 +8211,7 @@ set_init_index (location_t loc, tree first, tree last, /* Within a struct initializer, specify the next field to be initialized. */ void -set_init_label (location_t loc, tree fieldname, +set_init_label (location_t loc, tree fieldname, location_t fieldname_loc, struct obstack *braced_init_obstack) { tree field; @@ -8230,7 +8230,24 @@ set_init_label (location_t loc, tree fieldname, field = lookup_field (constructor_type, fieldname); if (field == 0) - error_at (loc, "unknown field %qE specified in initializer", fieldname); + { + tree guessed_id = lookup_field_fuzzy (constructor_type, fieldname); + if (guessed_id) + { + rich_location rich_loc (line_table, fieldname_loc); + source_range component_range = + get_range_from_loc (line_table, fieldname_loc); + rich_loc.add_fixit_replace (component_range, + IDENTIFIER_POINTER (guessed_id)); + error_at_rich_loc + (&rich_loc, + "%qT has no member named %qE; did you mean %qE?", + constructor_type, fieldname, guessed_id); + } + else + error_at (fieldname_loc, "%qT has no member named %qE", + constructor_type, fieldname); + } else do { |