diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 7a27244..58708da 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1295,9 +1295,9 @@ static struct c_type_name *c_parser_type_name (c_parser *); static struct c_expr c_parser_initializer (c_parser *); static struct c_expr c_parser_braced_init (c_parser *, tree, bool, struct obstack *); -static void c_parser_initelt (c_parser *, struct obstack *); +static void c_parser_initelt (c_parser *, struct obstack *, bool *); static void c_parser_initval (c_parser *, struct c_expr *, - struct obstack *); + struct obstack *, bool *); static tree c_parser_compound_statement (c_parser *); static void c_parser_compound_statement_nostart (c_parser *); static void c_parser_label (c_parser *); @@ -4352,9 +4352,10 @@ c_parser_braced_init (c_parser *parser, tree type, bool nested_p, { /* Parse a non-empty initializer list, possibly with a trailing comma. */ + bool warn_extra_init = true; while (true) { - c_parser_initelt (parser, &braced_init_obstack); + c_parser_initelt (parser, &braced_init_obstack, &warn_extra_init); if (parser->error) break; if (c_parser_next_token_is (parser, CPP_COMMA)) @@ -4387,7 +4388,7 @@ c_parser_braced_init (c_parser *parser, tree type, bool nested_p, /* Parse a nested initializer, including designators. */ static void -c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) +c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack, bool *warn_extra_init) { /* Parse any designator or designator list. A single array designator may have the subsequent "=" omitted in GNU C, but a @@ -4439,7 +4440,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_COMMA, NULL); process_init_element (input_location, init, false, - braced_init_obstack); + braced_init_obstack); return; } } @@ -4521,7 +4522,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) /* Now parse and process the remainder of the initializer, starting with this message expression as a primary-expression. */ - c_parser_initval (parser, &mexpr, braced_init_obstack); + c_parser_initval (parser, &mexpr, braced_init_obstack, warn_extra_init); return; } c_parser_consume_token (parser); @@ -4575,13 +4576,13 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) c_parser_error (parser, "expected %<=%>"); c_parser_skip_until_found (parser, CPP_COMMA, NULL); process_init_element (input_location, init, false, - braced_init_obstack); + braced_init_obstack); return; } } } } - c_parser_initval (parser, NULL, braced_init_obstack); + c_parser_initval (parser, NULL, braced_init_obstack, warn_extra_init); } /* Parse a nested initializer; as c_parser_initializer but parses @@ -4592,7 +4593,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) static void c_parser_initval (c_parser *parser, struct c_expr *after, - struct obstack * braced_init_obstack) + struct obstack * braced_init_obstack, bool *warn_extra_init) { struct c_expr init; gcc_assert (!after || c_dialect_objc ()); @@ -4609,7 +4610,7 @@ c_parser_initval (c_parser *parser, struct c_expr *after, && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR) init = convert_lvalue_to_rvalue (loc, init, true, true); } - process_init_element (loc, init, false, braced_init_obstack); + process_init_element (loc, init, false, braced_init_obstack, warn_extra_init); } /* Parse a compound statement (possibly a function body) (C90 6.6.2, diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 96ab049..6b9d442 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -631,7 +631,7 @@ 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 process_init_element (location_t, struct c_expr, bool, - struct obstack *); + struct obstack *, bool *warn_extra_init = NULL); extern tree build_compound_literal (location_t, tree, tree, bool); extern void check_compound_literal_type (location_t, struct c_type_name *); extern tree c_start_case (location_t, location_t, tree, bool); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 1122a88..d0cbcfc 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -8967,7 +8967,7 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack) void process_init_element (location_t loc, struct c_expr value, bool implicit, - struct obstack * braced_init_obstack) + struct obstack * braced_init_obstack, bool *warn_extra_init) { tree orig_value = value.value; int string_flag = orig_value != 0 && TREE_CODE (orig_value) == STRING_CST; @@ -9269,9 +9269,13 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, && (tree_int_cst_lt (constructor_max_index, constructor_index) || integer_all_onesp (constructor_max_index))) { - pedwarn_init (loc, 0, - "excess elements in array initializer"); - break; + if (warn_extra_init && *warn_extra_init == true) + { + pedwarn_init (loc, 0, + "excess elements in array initializer"); + *warn_extra_init = false; + break; + } } /* Now output the actual element. */