decl.c (make_typename_type): Revert.
authorJason Merrill <jason@yorick.cygnus.com>
Mon, 23 Mar 1998 23:08:59 +0000 (23:08 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 23 Mar 1998 23:08:59 +0000 (18:08 -0500)
* decl.c (make_typename_type): Revert.
(make_implicit_typename): Remove.
(lookup_name_real): Don't call it.  Call lookup_field if we see a
TYPE_DECL from a template base.
* search.c (lookup_field): Do implicit typename stuff.

From-SVN: r18790

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/search.c

index b3fe9fc99351a44f9a4c96d47cafa436d10b9e68..291ceabd208733e52d479124a98d0845fdeefc18 100644 (file)
@@ -1,3 +1,11 @@
+Mon Mar 23 12:24:37 1998  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * decl.c (make_typename_type): Revert.
+       (make_implicit_typename): Remove.
+       (lookup_name_real): Don't call it.  Call lookup_field if we see a
+       TYPE_DECL from a template base.
+       * search.c (lookup_field): Do implicit typename stuff.
+
 Sun Mar 22 00:50:42 1998  Nick Clifton  <nickc@cygnus.com>
                           Geoff Noer    <noer@cygnus.com>
 
index 434d84c3cdc65dfc352702b9d3eab8b56f011ee7..7f2df3f82805109fe3e2baa1cb22e2c9da27e147 100644 (file)
@@ -4555,14 +4555,6 @@ make_typename_type (context, name)
              return error_mark_node;
            }
 
-         /* If this is really from a base that uses template parms,
-            push the TYPENAME_TYPE down.  */
-         if (processing_template_decl
-             && context == current_class_type
-             && DECL_CONTEXT (t) != context
-             && uses_template_parms (DECL_CONTEXT (t)))
-           return make_implicit_typename (context, t);
-
          return TREE_TYPE (t);
        }
     }
@@ -4584,49 +4576,6 @@ make_typename_type (context, name)
   return t;
 }
 
-/* Given a TYPE_DECL T looked up in CONTEXT, return a TYPENAME_TYPE
-   where the scope is the first class along the inheritance chain to T
-   that is not current_class_type.
-
-   Called from lookup_name_real to implement the implicit typename
-   extension.  */
-
-static tree
-make_implicit_typename (context, t)
-     tree context, t;
-{
-  tree retval;
-
-  if (context == current_class_type)
-    {
-      tree binfos = TYPE_BINFO_BASETYPES (context);
-      int n_baselinks = TREE_VEC_LENGTH (binfos);
-      int i;
-
-      /* We can't use DECL_CONTEXT (t) to help us here, because it refers
-        to the uninstantiated template type that t comes from, which is
-        probably not a base of ours.  This happens because we don't
-         actually do partial instantiation of types in
-         instantiate_class_template.  */
-
-      for (i = 0; i < n_baselinks; ++i)
-       {
-         tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
-         if (lookup_field (basetype, DECL_NAME (t), 0, 1))
-           {
-             context = basetype;
-             break;
-           }
-       }
-    }
-
-  retval = make_typename_type (context, DECL_NAME (t));
-
-  if (TREE_CODE (retval) == TYPENAME_TYPE)
-    TREE_TYPE (retval) = TREE_TYPE (t);
-  return retval;
-}
-
 /* Look up NAME in the current binding level and its superiors in the
    namespace of variables, functions and typedefs.  Return a ..._DECL
    node of some kind representing its definition if there is only one
@@ -4716,17 +4665,6 @@ lookup_name_real (name, prefer_type, nonclass)
       else
        val = NULL_TREE;
 
-      /* Add implicit 'typename' to scoped types from other classes.  */
-      if (got_scope && processing_template_decl
-         && got_scope != current_class_type
-         && uses_template_parms (got_scope)
-         && val && TREE_CODE (val) == TYPE_DECL
-         && ! DECL_ARTIFICIAL (val))
-       {
-         tree t = make_implicit_typename (got_scope, val);
-         val = TYPE_MAIN_DECL (t);
-       }
-
       if (got_scope)
        goto done;
       else if (got_object && val)
@@ -4756,16 +4694,14 @@ lookup_name_real (name, prefer_type, nonclass)
       if (classval == NULL_TREE)
        classval = lookup_nested_field (name, ! yylex);
 
-      /* Add implicit 'typename' to types from base classes.  */
+      /* Add implicit 'typename' to types from template bases.  lookup_field
+         will do this for us.  */
       if (processing_template_decl
          && classval && TREE_CODE (classval) == TYPE_DECL
          && DECL_CONTEXT (classval) != current_class_type
-         && uses_template_parms (DECL_CONTEXT (classval))
+         && uses_template_parms (current_class_type)
          && ! DECL_ARTIFICIAL (classval))
-       {
-         tree t = make_implicit_typename (current_class_type, classval);
-         classval = TYPE_MAIN_DECL (t);
-       }
+       classval = lookup_field (current_class_type, name, 0, 1);
     }
 
   if (locval && classval)
index a12ebf4eb47f5b5de9a6c891f0ba0fa2810f3173..fe0a3a419662bb8e6e9ff5ed9af38b1f1ad85aa7 100644 (file)
@@ -1304,28 +1304,8 @@ lookup_field (xbasetype, name, protect, want_type)
            }
        }
 
-      if (entry)
-       {
-         if (errstr)
-           {
-             /* This depends on behavior of lookup_field_1!  */
-             tree error_string = my_build_string (errstr);
-             TREE_TYPE (entry) = error_string;
-           }
-         else
-           {
-             /* Let entry know there is no problem with this access.  */
-             TREE_TYPE (entry) = NULL_TREE;
-           }
-         TREE_VALUE (entry) = rval;
-       }
-
-      if (errstr && protect)
-       {
-         cp_error (errstr, name, type);
-         return error_mark_node;
-       }
-      return rval;
+      rval_binfo = basetype_path;
+      goto out;
     }
 
   basetype_chain = build_expr_list (NULL_TREE, basetype_path);
@@ -1522,6 +1502,7 @@ lookup_field (xbasetype, name, protect, want_type)
            : "member `%D' is from protected base class";
     }
 
+ out:
   if (entry)
     {
       if (errstr)
@@ -1550,6 +1531,26 @@ lookup_field (xbasetype, name, protect, want_type)
       cp_error (errstr, name, type);
       rval = error_mark_node;
     }
+
+  /* Do implicit typename stuff.  */
+  if (rval && TREE_CODE (rval) == TYPE_DECL
+      && ! DECL_ARTIFICIAL (rval)
+      && processing_template_decl
+      && BINFO_TYPE (rval_binfo) != current_class_type
+      && uses_template_parms (type))
+    {
+      binfo = rval_binfo;
+      for (; ; binfo = BINFO_INHERITANCE_CHAIN (binfo))
+       if (BINFO_INHERITANCE_CHAIN (binfo) == NULL_TREE
+           || (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo))
+               == current_class_type))
+         break;
+
+      entry = make_typename_type (BINFO_TYPE (binfo), name);
+      TREE_TYPE (entry) = TREE_TYPE (rval);
+      rval = TYPE_MAIN_DECL (entry);
+    }
+
   return rval;
 }