From d50c6443101f1ffc06932e997b22a566b45907f7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sun, 29 Mar 1998 20:04:28 +0000 Subject: [PATCH] friend.c (is_friend): Local classes have the same access as the enclosing function. * friend.c (is_friend): Local classes have the same access as the enclosing function. From-SVN: r18904 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/friend.c | 37 +++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b4830ed7ece..62780a46737 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +Sun Mar 29 20:01:59 1998 Jason Merrill + + * 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. diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c index f28e049cfa4..d0e6fefbff8 100644 --- a/gcc/cp/friend.c +++ b/gcc/cp/friend.c @@ -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; } -- 2.30.2