Bug 84493 - [8 Regression] ICE with invalid cast
Summary: [8 Regression] ICE with invalid cast
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Marek Polacek
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2018-02-20 21:28 UTC by Volker Reichelt
Modified: 2018-02-22 11:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2018-02-20 21:28:41 UTC
The following invalid code snippet triggers an ICE on trunk:

=============================
void foo()
{
  (struct {}x){};
}
=============================

bug.cc: In function 'void foo()':
bug.cc:3:13: error: expected ')' before 'x'
   (struct {}x){};
   ~         ^
             )
bug.cc:3:13: internal compiler error: in consume_open, at cp/parser.c:4711
0x6250d2 token_pair<matching_brace_traits>::consume_open(cp_parser*)
	../../gcc/gcc/cp/parser.c:4711
0x626972 token_pair<matching_brace_traits>::consume_open(cp_parser*)
	../../gcc/gcc/tree.h:3246
0x626972 cp_parser_braced_list
	../../gcc/gcc/cp/parser.c:21928
0x930d90 cp_parser_postfix_expression
	../../gcc/gcc/cp/parser.c:6989
0x931010 cp_parser_unary_expression
	../../gcc/gcc/cp/parser.c:8318
0x91139f cp_parser_cast_expression
	../../gcc/gcc/cp/parser.c:9086
0x911baa cp_parser_binary_expression
	../../gcc/gcc/cp/parser.c:9187
0x9133e4 cp_parser_assignment_expression
	../../gcc/gcc/cp/parser.c:9482
0x913af8 cp_parser_expression
	../../gcc/gcc/cp/parser.c:9651
0x9157b8 cp_parser_expression_statement
	../../gcc/gcc/cp/parser.c:11118
0x91bb2d cp_parser_statement
	../../gcc/gcc/cp/parser.c:10922
0x91d040 cp_parser_statement_seq_opt
	../../gcc/gcc/cp/parser.c:11261
0x91d117 cp_parser_compound_statement
	../../gcc/gcc/cp/parser.c:11215
0x933890 cp_parser_function_body
	../../gcc/gcc/cp/parser.c:21756
0x933890 cp_parser_ctor_initializer_opt_and_function_body
	../../gcc/gcc/cp/parser.c:21793
0x934140 cp_parser_function_definition_after_declarator
	../../gcc/gcc/cp/parser.c:26694
0x934e74 cp_parser_function_definition_from_specifiers_and_declarator
	../../gcc/gcc/cp/parser.c:26610
0x934e74 cp_parser_init_declarator
	../../gcc/gcc/cp/parser.c:19482
0x93bf08 cp_parser_simple_declaration
	../../gcc/gcc/cp/parser.c:13044
0x93cd18 cp_parser_block_declaration
	../../gcc/gcc/cp/parser.c:12869
Please submit a full bug report, [etc.]

The regression was introduced between 2017-08-10 and 2017-08-19.
Comment 1 Marek Polacek 2018-02-21 08:16:14 UTC
Confirmed, I think this is the fix:

--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -21925,7 +21925,7 @@ cp_parser_braced_list (cp_parser* parser, bool* non_constant_p)
 
   /* Consume the `{' token.  */
   matching_braces braces;
-  braces.consume_open (parser);
+  braces.require_open (parser);
   /* Create a CONSTRUCTOR to represent the braced-initializer.  */
   initializer = make_node (CONSTRUCTOR);
   /* If it's not a `}', then there is a non-trivial initializer.  */
Comment 2 Marek Polacek 2018-02-22 11:19:09 UTC
Author: mpolacek
Date: Thu Feb 22 11:18:37 2018
New Revision: 257899

URL: https://gcc.gnu.org/viewcvs?rev=257899&root=gcc&view=rev
Log:
	PR c++/84493
	* parser.c (cp_parser_braced_list): Use require_open instead of
	consume_open.

	* g++.dg/parse/error59.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/parse/error59.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Marek Polacek 2018-02-22 11:36:12 UTC
Fixed.