class.c (currently_open_class): New fn.
authorJason Merrill <jason@gcc.gnu.org>
Sat, 9 May 1998 18:10:28 +0000 (14:10 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 9 May 1998 18:10:28 +0000 (14:10 -0400)
* class.c (currently_open_class): New fn.
* decl.c (lookup_name_real): Use it.
* search.c (lookup_field): Likewise.

From-SVN: r19650

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

index 887026d..0006972 100644 (file)
@@ -1,4 +1,10 @@
-Mon Apr 27 07:17:38 1998  Martin von Loewis  <loewis@informatik.hu-berlin.de>
+Sat May  9 14:44:37 1998  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * class.c (currently_open_class): New fn.
+       * decl.c (lookup_name_real): Use it.
+       * search.c (lookup_field): Likewise.
+
+Fri May  8 23:32:42 1998  Martin von Loewis  <loewis@informatik.hu-berlin.de>
 
        * cp-tree.def (OVERLOAD): New node.  
        * cp-tree.h (BINDING_TYPE, SET_IDENTIFIER_GLOBAL_VALUE,
index fe5b861..0e3e3cd 100644 (file)
@@ -4822,6 +4822,21 @@ popclass (modify)
   ;
 }
 
+/* Returns 1 if current_class_type is either T or a nested type of T.  */
+
+int
+currently_open_class (t)
+     tree t;
+{
+  int i;
+  if (t == current_class_type)
+    return 1;
+  for (i = 0; i < current_class_depth; ++i)
+    if (current_class_stack [-i*2 - 1] == t)
+      return 1;
+  return 0;
+}
+
 /* When entering a class scope, all enclosing class scopes' names with
    static meaning (static variables, static functions, types and enumerators)
    have to be visible.  This recursive function calls pushclass for all
index c73bea1..d0afbc2 100644 (file)
@@ -4826,20 +4826,21 @@ lookup_name_real (name, prefer_type, nonclass)
           TYPE_DECLs.  */
        classval = lookup_field (current_class_type, name, 0, 1);
 
-      /* yylex() calls this with -2, since we should never start digging for
-        the nested name at the point where we haven't even, for example,
-        created the COMPONENT_REF or anything like that.  */
-      if (classval == NULL_TREE)
-       classval = lookup_nested_field (name, ! yylex);
-
       /* Add implicit 'typename' to types from template bases.  lookup_field
-         will do this for us.  */
+         will do this for us.  If classval is actually from an enclosing
+         scope, lookup_nested_field will get it for us.  */
       if (processing_template_decl
          && classval && TREE_CODE (classval) == TYPE_DECL
-         && DECL_CONTEXT (classval) != current_class_type
+         && ! currently_open_class (DECL_CONTEXT (classval))
          && uses_template_parms (current_class_type)
          && ! DECL_ARTIFICIAL (classval))
        classval = lookup_field (current_class_type, name, 0, 1);
+
+      /* yylex() calls this with -2, since we should never start digging for
+        the nested name at the point where we haven't even, for example,
+        created the COMPONENT_REF or anything like that.  */
+      if (classval == NULL_TREE)
+       classval = lookup_nested_field (name, ! yylex);
     }
 
   if (locval && classval)
index bbcf40c..08291a8 100644 (file)
@@ -1549,7 +1549,7 @@ lookup_field (xbasetype, name, protect, want_type)
   if (rval && TREE_CODE (rval) == TYPE_DECL
       && ! DECL_ARTIFICIAL (rval)
       && processing_template_decl
-      && BINFO_TYPE (rval_binfo) != current_class_type
+      && ! currently_open_class (BINFO_TYPE (rval_binfo))
       && uses_template_parms (type))
     {
       binfo = rval_binfo;
@@ -1577,14 +1577,14 @@ lookup_nested_field (name, complain)
   register tree t;
 
   tree id = NULL_TREE;
-  if (TREE_CHAIN (current_class_type))
+  if (TYPE_MAIN_DECL (current_class_type))
     {
       /* Climb our way up the nested ladder, seeing if we're trying to
         modify a field in an enclosing class.  If so, we should only
         be able to modify if it's static.  */
-      for (t = TREE_CHAIN (current_class_type);
+      for (t = TYPE_MAIN_DECL (current_class_type);
           t && DECL_CONTEXT (t);
-          t = TREE_CHAIN (DECL_CONTEXT (t)))
+          t = TYPE_MAIN_DECL (DECL_CONTEXT (t)))
        {
          if (TREE_CODE (DECL_CONTEXT (t)) != RECORD_TYPE)
            break;