diff options
author | Jakub Jelinek <jakub@redhat.com> | 2011-01-21 22:34:25 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2011-01-21 22:34:25 +0100 |
commit | 95cc031fd89f7e05a2653ec098105e29817ed6ea (patch) | |
tree | 31842ab7308fede4f5d7a2642f1c261de4853b35 /gcc | |
parent | abba182313a491dae23985a480944282c6a566a8 (diff) | |
download | gcc-95cc031fd89f7e05a2653ec098105e29817ed6ea.zip gcc-95cc031fd89f7e05a2653ec098105e29817ed6ea.tar.gz gcc-95cc031fd89f7e05a2653ec098105e29817ed6ea.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/range-for10.C | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/for1.C | 23 |
5 files changed, 59 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 08d7a6d..0e7bcb0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2011-01-21 Jakub Jelinek <jakub@redhat.com> + + 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 <jason@redhat.com> PR c++/46552 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fa35d4a..ba90515 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 657a61d..5e1539b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2011-01-21 Jakub Jelinek <jakub@redhat.com> + 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 0000000..6620748 --- /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 <int> +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 0000000..dc33afc --- /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 <int> +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> (); +} |