Patchwork C++ PATCH for c++/50114 (ICE with for-loop and lambda)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 30, 2011, 9:36 p.m.
Message ID <4E5D57E3.4010707@redhat.com>
Download mbox | patch
Permalink /patch/112388/
State New
Headers show

Comments

Jason Merrill - Aug. 30, 2011, 9:36 p.m.
We play funny games with binding levels to support backward 
compatibility with the ARM-era rules for for-loop scoping, and we play 
funny games with binding levels to support lambdas, and the games didn't 
play well with each other.  It seems unlikely that people will still be 
relying on ancient for scope rules in C++11 code, so we can just disable 
those games in C++11 mode.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 03b745415d2109312c4449479c2f94e65bd770b4
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Aug 30 14:32:54 2011 -0400

    	PR c++/50114
    	* decl.c (poplevel): Disable for scope compatibility hack
    	in C++11 mode.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c375cf7..9090b11 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -643,6 +643,9 @@  poplevel (int keep, int reverse, int functionbody)
   for (link = decls; link; link = TREE_CHAIN (link))
     {
       if (leaving_for_scope && TREE_CODE (link) == VAR_DECL
+	  /* It's hard to make this ARM compatibility hack play nicely with
+	     lambdas, and it really isn't necessary in C++11 mode.  */
+	  && cxx_dialect < cxx0x
 	  && DECL_NAME (link))
 	{
 	  tree name = DECL_NAME (link);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-for.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-for.C
new file mode 100644
index 0000000..f161da8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-for.C
@@ -0,0 +1,12 @@ 
+// PR c++/50114
+// { dg-options "-std=c++0x -w" }
+
+int open()
+{
+  int *x2feed_i = 0;
+  auto insert_feed = [&](unsigned char venue, int* newfeed)
+  {
+     for(int x2feed_i = 1; 0; ) ;
+     x2feed_i = newfeed;
+  };
+}
diff --git a/gcc/testsuite/g++.dg/ext/forscope2.C b/gcc/testsuite/g++.dg/ext/forscope2.C
index b883eff..4c63bab 100644
--- a/gcc/testsuite/g++.dg/ext/forscope2.C
+++ b/gcc/testsuite/g++.dg/ext/forscope2.C
@@ -1,5 +1,5 @@ 
 // { dg-do compile }
-// { dg-options -fpermissive }
+// { dg-options "-fpermissive -std=c++98" }
 
 // Copyright (C) 2001 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 4 Sept 2001 <nathan@codesourcery.com>