From 95cc031fd89f7e05a2653ec098105e29817ed6ea Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 21 Jan 2011 22:34:25 +0100 Subject: [PATCH] re PR c++/47388 (ICE: in begin_for_stmt, at cp/semantics.c:863 with -fno-for-scope and for(;;) inside a template) PR c++/47388 * semantics.c (begin_for_stmt): If -fno-for-scope, don't assume init must be NULL if scope is NULL. (begin_range_for_stmt): Likewise. * g++.dg/cpp0x/range-for10.C: New test. * g++.dg/template/for1.C: New test. From-SVN: r169105 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/semantics.c | 12 +++++++----- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/range-for10.C | 18 ++++++++++++++++++ gcc/testsuite/g++.dg/template/for1.C | 23 +++++++++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/range-for10.C create mode 100644 gcc/testsuite/g++.dg/template/for1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 08d7a6d8e74..0e7bcb0ce29 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2011-01-21 Jakub Jelinek + + PR c++/47388 + * semantics.c (begin_for_stmt): If -fno-for-scope, don't + assume init must be NULL if scope is NULL. + (begin_range_for_stmt): Likewise. + 2011-01-21 Jason Merrill PR c++/46552 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fa35d4ae990..ba9051592bf 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -4,7 +4,7 @@ and during the instantiation of template functions. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009, 2010 Free Software Foundation, Inc. + 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Written by Mark Mitchell (mmitchell@usa.net) based on code found formerly in parse.y and pt.c. @@ -860,8 +860,9 @@ begin_for_stmt (tree scope, tree init) if (scope == NULL_TREE) { - gcc_assert (!init); - scope = begin_for_scope (&init); + gcc_assert (!init || !(flag_new_for_scope > 0)); + if (!init) + scope = begin_for_scope (&init); } FOR_INIT_STMT (r) = init; TREE_CHAIN (r) = scope; @@ -962,8 +963,9 @@ begin_range_for_stmt (tree scope, tree init) if (scope == NULL_TREE) { - gcc_assert (!init); - scope = begin_for_scope (&init); + gcc_assert (!init || !(flag_new_for_scope > 0)); + if (!init) + scope = begin_for_scope (&init); } /* RANGE_FOR_STMTs do not use nor save the init tree, so we diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 657a61d9c32..5e1539bf513 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2011-01-21 Jakub Jelinek + PR c++/47388 + * g++.dg/cpp0x/range-for10.C: New test. + * g++.dg/template/for1.C: New test. + PR middle-end/45566 * g++.dg/tree-prof/partition3.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for10.C b/gcc/testsuite/g++.dg/cpp0x/range-for10.C new file mode 100644 index 00000000000..662074890d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for10.C @@ -0,0 +1,18 @@ +// PR c++/47388 +// { dg-do compile } +// { dg-options "-fno-for-scope -std=c++0x" } + +template +void +foo () +{ + int a[] = { 1, 2, 3, 4 }; + for (int i : a) + ; +} + +void +bar () +{ + foo <0> (); +} diff --git a/gcc/testsuite/g++.dg/template/for1.C b/gcc/testsuite/g++.dg/template/for1.C new file mode 100644 index 00000000000..dc33afcdaec --- /dev/null +++ b/gcc/testsuite/g++.dg/template/for1.C @@ -0,0 +1,23 @@ +// PR c++/47388 +// { dg-do compile } +// { dg-options "-fno-for-scope" } + +template +void +foo () +{ + int i; + for (i = 0; i < 16; i++) + ; + for (int j = 0; j < 16; j++) + ; + if (j != 16) + for (;;) + ; +} + +void +bar () +{ + foo <0> (); +} -- 2.30.2