[PR,c++/84836] ICE with local scopes

Message ID 733d0af5-512d-05b3-eb36-6bf8a70d82fc@acm.org
State New
Headers show
Series
  • [PR,c++/84836] ICE with local scopes
Related show

Commit Message

Nathan Sidwell March 21, 2018, 10:58 a.m.
I'd flubbed the condition on when a local binding was updated, leading 
to an ICE when popping them.  For a local overload set we need to look 
in the binding list and find the one to update.  We didn't do that when 
we'd already hidden a TYPE_DECL of the same name.

Fixed thusly.

nathan
-- 
Nathan Sidwell

Patch

2018-03-21  Nathan Sidwell  <nathan@acm.org>

	PR c++/84836
	* name-lookup.c (update_binding): Correct logic for local binding
	update.

	PR c++/84836
	* g++.dg/lookup/pr84836.C: New.

Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c	(revision 258710)
+++ gcc/cp/name-lookup.c	(working copy)
@@ -2481,21 +2481,12 @@  update_binding (cp_binding_level *level,
  done:
   if (to_val)
     {
-      if (level->kind != sk_namespace
-	  && !to_type && binding->value && OVL_P (to_val))
-	update_local_overload (binding, to_val);
+      if (level->kind == sk_namespace || to_type == decl || to_val == decl)
+	add_decl_to_level (level, decl);
       else
 	{
-	  tree to_add = to_val;
-      
-	  if (level->kind == sk_namespace)
-	    to_add = decl;
-	  else if (to_type == decl)
-	    to_add = decl;
-	  else if (TREE_CODE (to_add) == OVERLOAD)
-	    to_add = build_tree_list (NULL_TREE, to_add);
-
-	  add_decl_to_level (level, to_add);
+	  gcc_checking_assert (binding->value && OVL_P (binding->value));
+	  update_local_overload (binding, to_val);
 	}
 
       if (slot)
Index: gcc/testsuite/g++.dg/lookup/pr84836.C
===================================================================
--- gcc/testsuite/g++.dg/lookup/pr84836.C	(revision 0)
+++ gcc/testsuite/g++.dg/lookup/pr84836.C	(working copy)
@@ -0,0 +1,9 @@ 
+// PR c++/84836
+// ICE popping local binding
+
+void foo (void)
+{
+  struct A;
+  void A (int);
+  void A (long);
+}