[gcc/devel/c++-modules] c++: Identifier type value should not update binding (trunk cc61827b55e)

Nathan Sidwell nathan@gcc.gnu.org
Wed Sep 30 20:27:16 GMT 2020


https://gcc.gnu.org/g:c109cb93360faa53f9964f5d0f29a1f424f37596

commit c109cb93360faa53f9964f5d0f29a1f424f37596
Author: Nathan Sidwell <nathan@acm.org>
Date:   Wed Sep 30 11:08:24 2020 -0700

    c++: Identifier type value should not update binding (trunk cc61827b55e)

Diff:
---
 ChangeLog.modules    |  3 +++
 gcc/cp/name-lookup.c | 62 +++++++++++++++++++++++-----------------------------
 2 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/ChangeLog.modules b/ChangeLog.modules
index 377d976b9a5..21eeaa7df14 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,5 +1,8 @@
 2020-09-30  Nathan Sidwell  <nathan@acm.org>
 
+	Apply trunk cc61827b55e
+	c++: Identifier type value should not update binding
+
 	Merge trunk c74e6f7cfd7
 	c++: Adjust pushdecl/duplicate_decls API
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index ab31b191545..083cb839df9 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -2956,33 +2956,24 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot,
   if (old == error_mark_node)
     old = NULL_TREE;
 
-  if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl))
+  if (DECL_IMPLICIT_TYPEDEF_P (decl))
     {
-      tree other = to_type;
-
-      if (old && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
-	other = old;
-
-      /* Pushing an artificial typedef.  See if this matches either
-	 the type slot or the old value slot.  */
-      if (!other)
-	;
-      else if (same_type_p (TREE_TYPE (other), TREE_TYPE (decl)))
-	/* Two artificial decls to same type.  Do nothing.  */
-	return other;
-      else
-	goto conflict;
+      /* Pushing an artificial decl.  We should not find another
+         artificial decl here already -- lookup_elaborated_type will
+         have already found it.  */
+      gcc_checking_assert (!to_type
+			   && !(old && DECL_IMPLICIT_TYPEDEF_P (old)));
 
       if (old)
 	{
 	  /* Slide decl into the type slot, keep old unaltered  */
 	  to_type = decl;
 	  to_val = old;
-	  goto done;
 	}
+      goto done;
     }
 
-  if (old && TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
+  if (old && DECL_IMPLICIT_TYPEDEF_P (old))
     {
       /* Slide old into the type slot.  */
       to_type = old;
@@ -3607,18 +3598,13 @@ newbinding_bookkeeping (tree name, tree decl, cp_binding_level *level)
 	  if (TYPE_NAME (type) != decl)
 	    set_underlying_type (decl);
 
-	  if (level->kind == sk_namespace)
-	    SET_IDENTIFIER_TYPE_VALUE (name, global_type_node);
-	  else
-	    {
-	      set_identifier_type_value_with_scope (name, decl, level);
+	  set_identifier_type_value_with_scope (name, decl, level);
 
-	      /* If this is a locally defined typedef in a function
-		 that is not a template instantation, record it to
-		 implement -Wunused-local-typedefs.  */
-	      if (!instantiating_current_function_p ())
-		record_locally_defined_typedef (decl);
-	    }
+	  if (level->kind != sk_namespace && !instantiating_current_function_p ())
+	    /* If this is a locally defined typedef in a function that
+	       is not a template instantation, record it to implement
+	       -Wunused-local-typedefs.  */
+	    record_locally_defined_typedef (decl);
 	}
     }
   else if (VAR_P (decl))
@@ -3926,7 +3912,7 @@ do_pushdecl (tree decl, bool hiding)
 
 	  if (TREE_CODE (decl) == NAMESPACE_DECL)
 	    /* A local namespace alias.  */
-	    set_identifier_type_value (name, NULL_TREE);
+	    set_identifier_type_value_with_scope (name, NULL_TREE, level);
 
 	  if (!binding)
 	    binding = create_local_binding (level, name);
@@ -4895,8 +4881,9 @@ identifier_type_value (tree id)
 }
 
 /* Push a definition of struct, union or enum tag named ID.  into
-   binding_level B.  DECL is a TYPE_DECL for the type.  We assume that
-   the tag ID is not already defined.  */
+   binding_level B.  DECL is a TYPE_DECL for the type.  DECL has
+   already been pushed into its binding level.  This is bookkeeping to
+   find it easily.  */
 
 static void
 set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b)
@@ -4908,20 +4895,25 @@ set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b)
       /* Shadow the marker, not the real thing, so that the marker
 	 gets restored later.  */
       tree old_type_value = REAL_IDENTIFIER_TYPE_VALUE (id);
-      b->type_shadowed
-	= tree_cons (id, old_type_value, b->type_shadowed);
+      b->type_shadowed = tree_cons (id, old_type_value, b->type_shadowed);
       type = decl ? TREE_TYPE (decl) : NULL_TREE;
       TREE_TYPE (b->type_shadowed) = type;
     }
   else
     {
-      tree *slot = find_namespace_slot (current_namespace, id, true);
       gcc_assert (decl);
-      update_binding (b, NULL, slot, MAYBE_STAT_DECL (*slot), decl);
+      if (false && CHECKING_P)
+	{
+	  tree *slot = find_namespace_slot (current_namespace, id);
+	  gcc_checking_assert (slot
+			       && (decl == MAYBE_STAT_TYPE (*slot)
+				   || decl == MAYBE_STAT_DECL (*slot)));
+	}
 
       /* Store marker instead of real type.  */
       type = global_type_node;
     }
+
   SET_IDENTIFIER_TYPE_VALUE (id, type);
 }


More information about the Gcc-cvs mailing list