friend.c (is_friend): Local classes have the same access as the enclosing function.
authorJason Merrill <jason@yorick.cygnus.com>
Sun, 29 Mar 1998 20:04:28 +0000 (20:04 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 29 Mar 1998 20:04:28 +0000 (15:04 -0500)
* friend.c (is_friend): Local classes have the same access as the
enclosing function.

From-SVN: r18904

gcc/cp/ChangeLog
gcc/cp/friend.c

index b4830ed7ecef22e32d2eb9be9833a5b9ffe30b53..62780a4673719db424d9be9fcf8bdea62bbdf799 100644 (file)
@@ -1,3 +1,8 @@
+Sun Mar 29 20:01:59 1998  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * friend.c (is_friend): Local classes have the same access as the
+       enclosing function.
+
 Sun Mar 29 00:47:32 1998  Jeffrey A Law  (law@cygnus.com)
 
        * typeck.c (expand_target_expr): Delete dead function.
index f28e049cfa4b46f1b44579cdf1a9310085822ad6..d0e6fefbff828cd93ef1d9cbfcbeb7f86fc6212b 100644 (file)
@@ -41,12 +41,21 @@ is_friend (type, supplicant)
 {
   int declp;
   register tree list;
+  tree context;
 
   if (supplicant == NULL_TREE || type == NULL_TREE)
     return 0;
 
   declp = (TREE_CODE_CLASS (TREE_CODE (supplicant)) == 'd');
 
+  /* Local classes have the same access as the enclosing function.  */
+  context = hack_decl_function_context (supplicant);
+  if (context)
+    {
+      supplicant = context;
+      declp = 1;
+    }
+
   if (declp)
     /* It's a function decl.  */
     {
@@ -113,26 +122,14 @@ is_friend (type, supplicant)
          return 1;
     }      
 
-  {
-    tree context;
-
-    if (! declp)
-      {
-       /* Are we a nested or local class?  If so, we aren't friends
-           with the CONTEXT.  */
-       if (IS_AGGR_TYPE (supplicant))
-         context = NULL_TREE;
-       else
-         context = DECL_CONTEXT (TYPE_MAIN_DECL (supplicant));
-      }
-    else if (DECL_FUNCTION_MEMBER_P (supplicant))
-      context = DECL_CLASS_CONTEXT (supplicant);
-    else
-      context = NULL_TREE;
-
-    if (context)
-      return is_friend (type, context);
-  }
+  if (declp && DECL_FUNCTION_MEMBER_P (supplicant))
+    context = DECL_CLASS_CONTEXT (supplicant);
+  else
+    /* Nested classes don't inherit the access of their enclosing class.  */
+    context = NULL_TREE;
+
+  if (context)
+    return is_friend (type, context);
 
   return 0;
 }