http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39858
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic --- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-03-31 01:25:53 UTC --- This patch does what you want, but it probably fails in unexpected ways because some callers to cp_parser_primary_expression expect it to give the error itself, so they won't actually emit an error. One would need to check error_mark_node in all callers and give an appropriate diagnostic. Even if someone did that work, I still doubt it will be accepted. Index: parser.c =================================================================== --- parser.c (revision 184424) +++ parser.c (working copy) @@ -4379,11 +4379,11 @@ cp_parser_primary_expression (cp_parser return decl; } /* Anything else is an error. */ default: - cp_parser_error (parser, "expected primary-expression"); + /* cp_parser_error (parser, "expected primary-expression");*/ return error_mark_node; } } /* Parse an id-expression. @@ -5862,12 +5862,14 @@ cp_parser_postfix_open_square_expression { bool expr_nonconst_p; maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS); index = cp_parser_braced_list (parser, &expr_nonconst_p); } - else + else index = cp_parser_expression (parser, /*cast_p=*/false, NULL); + if (index == error_mark_node) + error_at (input_location, "missing subscript"); } /* Look for the closing `]'. */ cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE); An alternative would be to just give a normal error that is: @@ -4379,11 +4379,11 @@ cp_parser_primary_expression (cp_parser return decl; } /* Anything else is an error. */ default: - cp_parser_error (parser, "expected primary-expression"); + error ("expected expression"); return error_mark_node; } } /* Parse an id-expression.