decl.c (make_implicit_typename): New fn.
authorJason Merrill <jason@yorick.cygnus.com>
Wed, 19 Nov 1997 18:42:13 +0000 (18:42 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 19 Nov 1997 18:42:13 +0000 (13:42 -0500)
* decl.c (make_implicit_typename): New fn.
(lookup_name_real): Use it.  Use current_class_type as the context.

From-SVN: r16581

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

index 9fb7f04fab6d35b36da2a6408d7694956caae8e4..efdf9a769e62ddb4e577e4660ae218c10e207ab1 100644 (file)
@@ -1,3 +1,8 @@
+Wed Nov 19 10:39:27 1997  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * decl.c (make_implicit_typename): New fn.
+       (lookup_name_real): Use it.  Use current_class_type as the context.
+
 Mon Nov 17 23:42:03 1997  Bruno Haible <haible@ilog.fr>
 
        * pt.c (do_poplevel): Don't prohibit jumps into this contour.
index 486897f0a950d2fc93e6d8e8b52f6d381d947a2a..e0158162e9dce01d6b7091b80a2d3fa2e49b23a4 100644 (file)
@@ -4372,6 +4372,40 @@ make_typename_type (context, name)
   return t;
 }
 
+/* Given a TYPE_DECL T looked up in CONTEXT, return a TYPENAME_TYPE
+   where the scope is either CONTEXT or the first base of CONTEXT along the
+   inheritance chain to T that depends on template parameters.
+
+   Called from lookup_name_real to implement the implicit typename
+   extension.  */
+
+static tree
+make_implicit_typename (context, t)
+     tree context, t;
+{
+  tree retval;
+
+  if (uses_template_parms (DECL_CONTEXT (t))
+      && DECL_CONTEXT (t) != context)
+    {
+      tree binfo = get_binfo (DECL_CONTEXT (t), context, 0);
+      for (;;)
+       {
+         tree next = BINFO_INHERITANCE_CHAIN (binfo);
+         if (! uses_template_parms (BINFO_TYPE (next))
+             || BINFO_TYPE (next) == context)
+           break;
+         binfo = next;
+       }
+      retval = make_typename_type (BINFO_TYPE (binfo), DECL_NAME (t));
+    }
+  else
+    retval = make_typename_type (context, DECL_NAME (t));
+  
+  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
@@ -4464,8 +4498,7 @@ lookup_name_real (name, prefer_type, nonclass)
          && val && TREE_CODE (val) == TYPE_DECL
          && ! DECL_ARTIFICIAL (val))
        {
-         tree t = make_typename_type (got_scope, DECL_NAME (val));
-         TREE_TYPE (t) = TREE_TYPE (val);
+         tree t = make_implicit_typename (got_scope, val);
          val = TYPE_MAIN_DECL (t);
        }
 
@@ -4505,9 +4538,7 @@ lookup_name_real (name, prefer_type, nonclass)
          && uses_template_parms (DECL_CONTEXT (classval))
          && ! DECL_ARTIFICIAL (classval))
        {
-         tree t = make_typename_type (DECL_CONTEXT (classval),
-                                      DECL_NAME (classval));
-         TREE_TYPE (t) = TREE_TYPE (classval);
+         tree t = make_implicit_typename (current_class_type, classval);
          classval = TYPE_MAIN_DECL (t);
        }
     }