Patchwork [obv] fix PR 46065, DECL_CHAIN conversion fallout

login
register
mail settings
Submitter Nathan Froyd
Date Nov. 10, 2010, 9:06 p.m.
Message ID <20101110210611.GR7991@nightcrawler>
Download mbox | patch
Permalink /patch/70692/
State New
Headers show

Comments

Nathan Froyd - Nov. 10, 2010, 9:06 p.m.
When iterating over `struct named_label_entry.names_in_scope', we need
to be careful as some of the entries may represent OVERLOADs instead of
the expected DECLs.  I kept the DECL_CHAIN for that far away and
glorious day when we have a statically typed IR.

Tested on x86_64-unknown-linux-gnu.  Committed as obvious.

-Nathan

gcc/cp/
	PR c++/46065
	* decl.c (poplevel_named_label_1): Use TREE_CHAIN if necessary.

gcc/testsuite/
	PR c++/46065
	* g++.dg/pr46065.C: New test.

Patch

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c372840..93af4b4 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -475,7 +475,11 @@  poplevel_named_label_1 (void **slot, void *data)
     {
       tree decl;
 
-      for (decl = ent->names_in_scope; decl; decl = DECL_CHAIN (decl))
+      /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
+	 TREE_LISTs representing OVERLOADs, so be careful.  */
+      for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
+						     ? DECL_CHAIN (decl)
+						     : TREE_CHAIN (decl)))
 	if (decl_jump_unsafe (decl))
 	  VEC_safe_push (tree, gc, ent->bad_decls, decl);
 
diff --git a/gcc/testsuite/g++.dg/pr46065.C b/gcc/testsuite/g++.dg/pr46065.C
new file mode 100644
index 0000000..75c171d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr46065.C
@@ -0,0 +1,11 @@ 
+// PR c++/46065
+// { dg-do compile }
+
+void bar ();
+
+void
+foo ()
+{
+  using ::bar;
+label:;
+}