https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91391
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- --- gcc/cp/parser.c.jj 2019-08-07 09:24:36.099089282 +0200 +++ gcc/cp/parser.c 2019-08-07 20:26:47.669663334 +0200 @@ -2102,7 +2102,7 @@ static cp_expr cp_parser_assignment_expr static enum tree_code cp_parser_assignment_operator_opt (cp_parser *); static cp_expr cp_parser_expression - (cp_parser *, cp_id_kind * = NULL, bool = false, bool = false); + (cp_parser *, cp_id_kind * = NULL, bool = false, bool = false, bool = false); static cp_expr cp_parser_constant_expression (cp_parser *, bool = false, bool * = NULL, bool = false); static cp_expr cp_parser_builtin_offsetof @@ -7524,33 +7524,9 @@ cp_parser_postfix_open_square_expression index = cp_parser_braced_list (parser, &expr_nonconst_p); } else - { - /* [depr.comma.subscript]: A comma expression appearing as - the expr-or-braced-init-list of a subscripting expression - is deprecated. A parenthesized comma expression is not - deprecated. */ - if (warn_comma_subscript) - { - /* Save tokens so that we can put them back. */ - cp_lexer_save_tokens (parser->lexer); - - /* Look for ',' that is not nested in () or {}. */ - if (cp_parser_skip_to_closing_square_bracket_1 (parser, - CPP_COMMA) == -1) - { - auto_diagnostic_group d; - warning_at (cp_lexer_peek_token (parser->lexer)->location, - OPT_Wcomma_subscript, - "top-level comma expression in array subscript " - "is deprecated"); - } - - /* Roll back the tokens we skipped. */ - cp_lexer_rollback_tokens (parser->lexer); - } - - index = cp_parser_expression (parser); - } + index = cp_parser_expression (parser, NULL, /*cast_p=*/false, + /*decltype_p=*/false, + /*warn_comma_p=*/warn_comma_subscript); } parser->greater_than_is_operator_p = saved_greater_than_is_operator_p; @@ -9932,12 +9908,13 @@ cp_parser_assignment_operator_opt (cp_pa CAST_P is true if this expression is the target of a cast. DECLTYPE_P is true if this expression is the immediate operand of decltype, except possibly parenthesized or on the RHS of a comma (N3276). + WARN_COMMA_P is true if a comma should be diagnosed. Returns a representation of the expression. */ static cp_expr cp_parser_expression (cp_parser* parser, cp_id_kind * pidk, - bool cast_p, bool decltype_p) + bool cast_p, bool decltype_p, bool warn_comma_p) { cp_expr expression = NULL_TREE; location_t loc = UNKNOWN_LOCATION; @@ -9984,6 +9961,17 @@ cp_parser_expression (cp_parser* parser, break; /* Consume the `,'. */ loc = cp_lexer_peek_token (parser->lexer)->location; + if (warn_comma_p) + { + /* [depr.comma.subscript]: A comma expression appearing as + the expr-or-braced-init-list of a subscripting expression + is deprecated. A parenthesized comma expression is not + deprecated. */ + warning_at (loc, OPT_Wcomma_subscript, + "top-level comma expression in array subscript " + "is deprecated"); + warn_comma_p = false; + } cp_lexer_consume_token (parser->lexer); /* A comma operator cannot appear in a constant-expression. */ if (cp_parser_non_integral_constant_expression (parser, NIC_COMMA)) Untested fix prior to any merging of bool flags. Guess that should be done incrementally if at all, so that the merit can be judged separately. Wonder about the auto_diagnostic_group d; in your earlier change, isn't something like that needed only if you call more than one diagnostic routine and want all of them being treated as a group? In this case there is just one warning_at, so it makes no sense to me. The cp_parser_namespace_name use doesn't make sense to me either.