Bug 85258 - [7/8 Regression] ICE with invalid range-based for-loop
Summary: [7/8 Regression] ICE with invalid range-based for-loop
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P4 normal
Target Milestone: 7.4
Assignee: Marek Polacek
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2018-04-06 12:47 UTC by Volker Reichelt
Modified: 2018-04-12 20:09 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-04-06 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-04-06 12:47:09 UTC
The following invalid code snippet triggers an ICE since GCC 7.1.0:

============================
template<int> void foo()
{
  int x[8];
  for (int& i, j : x)
    i = 0;
}

void bar()
{
  foo<0>();
}
============================

bug.cc: In function 'void foo()':
bug.cc:4:14: error: multiple declarations in range-based 'for' loop
   for (int& i, j : x)
              ^
bug.cc: In instantiation of 'void foo() [with int <anonymous> = 0]':
bug.cc:10:10:   required from here
bug.cc:5:5: internal compiler error: Segmentation fault
     i = 0;
     ^
0xebd87f crash_signal
	../../gcc/gcc/toplev.c:325
0x85245d reduced_constant_expression_p(tree_node*)
	../../gcc/gcc/cp/constexpr.c:1776
0x964822 tsubst_copy
	../../gcc/gcc/cp/pt.c:15142
0x9654ef tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../gcc/gcc/cp/pt.c:18526
0x966768 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../gcc/gcc/cp/pt.c:17467
0x965a96 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../gcc/gcc/cp/pt.c:17771
0x971627 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:17099
0x97092e tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16300
0x970f2c tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16495
0x97005c tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16286
0x96e71f tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16583
0x96d8b8 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../gcc/gcc/cp/pt.c:16271
0x96d8b8 instantiate_decl(tree_node*, bool, bool)
	../../gcc/gcc/cp/pt.c:23682
0x99476b instantiate_pending_templates(int)
	../../gcc/gcc/cp/pt.c:23798
0x8b8e3b c_parse_final_cleanups()
	../../gcc/gcc/cp/decl2.c:4725
Please submit a full bug report, [etc.]
Comment 1 Jakub Jelinek 2018-04-06 13:31:18 UTC
Started with r242422.
Comment 2 Marek Polacek 2018-04-12 20:03:18 UTC
Author: mpolacek
Date: Thu Apr 12 20:02:47 2018
New Revision: 259355

URL: https://gcc.gnu.org/viewcvs?rev=259355&root=gcc&view=rev
Log:
	PR c++/85258
	* constexpr.c (reduced_constant_expression_p): Return false for null
	trees.

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

Added:
    trunk/gcc/testsuite/g++.dg/parse/error61.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Marek Polacek 2018-04-12 20:09:41 UTC
Fixed.