diff mbox series

[2/2] c++: guard more against undiagnosed error_mark_node [PR112658]

Message ID 20231128165112.2571430-2-ppalka@redhat.com
State New
Headers show
Series [1/2] c++: casting array prvalue [PR112658, PR94264] | expand

Commit Message

Patrick Palka Nov. 28, 2023, 4:51 p.m. UTC
This adds a sanity check to cp_parser_expression_statement similar to
the one in finish_expr_stmt added by r6-6795-g0fd9d4921f7ba2, which
effectively downgrades accepts-invalid/wrong-code bugs like this one
into ice-on-invalid/ice-on-valid ones.

	PR c++/112658

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_expression_statement): If the statement
	is erroneous, make sure we've seen an error.
---
 gcc/cp/parser.cc | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jason Merrill Nov. 28, 2023, 9:33 p.m. UTC | #1
On 11/28/23 11:51, Patrick Palka wrote:
> This adds a sanity check to cp_parser_expression_statement similar to
> the one in finish_expr_stmt added by r6-6795-g0fd9d4921f7ba2, which
> effectively downgrades accepts-invalid/wrong-code bugs like this one
> into ice-on-invalid/ice-on-valid ones.

OK.

> 	PR c++/112658
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_expression_statement): If the statement
> 	is erroneous, make sure we've seen an error.
> ---
>   gcc/cp/parser.cc | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 2464d1a0783..743d6517b09 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -12962,6 +12962,9 @@ cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr)
>         if (statement == error_mark_node
>   	  && !cp_parser_uncommitted_to_tentative_parse_p (parser))
>   	{
> +	  /* If we ran into a problem, make sure we complained.  */
> +	  gcc_assert (seen_error ());
> +
>   	  cp_parser_skip_to_end_of_block_or_statement (parser);
>   	  return error_mark_node;
>   	}
diff mbox series

Patch

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 2464d1a0783..743d6517b09 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -12962,6 +12962,9 @@  cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr)
       if (statement == error_mark_node
 	  && !cp_parser_uncommitted_to_tentative_parse_p (parser))
 	{
+	  /* If we ran into a problem, make sure we complained.  */
+	  gcc_assert (seen_error ());
+
 	  cp_parser_skip_to_end_of_block_or_statement (parser);
 	  return error_mark_node;
 	}