re PR c++/47388 (ICE: in begin_for_stmt, at cp/semantics.c:863 with -fno-for-scope...
authorJakub Jelinek <jakub@redhat.com>
Fri, 21 Jan 2011 21:34:25 +0000 (22:34 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 21 Jan 2011 21:34:25 +0000 (22:34 +0100)
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
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/range-for10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/for1.C [new file with mode: 0644]

index 08d7a6d8e74551fdce5b5b8717a0433bb4a50526..0e7bcb0ce29224450ec079444754e3864368cb67 100644 (file)
@@ -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
index fa35d4ae99037f9b7decef95e3d35f919feb4d1d..ba9051592bf6e4b566c7c46e6c3f87c9d11ad861 100644 (file)
@@ -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
index 657a61d9c3248b1a615aae4bbb080c9edf05bc0a..5e1539bf5138bbad4bcc80a4a457e1b61d9d47ff 100644 (file)
@@ -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 (file)
index 0000000..6620748
--- /dev/null
@@ -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 (file)
index 0000000..dc33afc
--- /dev/null
@@ -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> ();
+}