From: Jason Merrill Date: Wed, 1 Apr 1998 17:05:25 +0000 (+0000) Subject: friend.c (is_friend): Fix access control for local classes. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=570221c20101ecc72f193e2b88e39069e05c963d;p=gcc.git friend.c (is_friend): Fix access control for local classes. * friend.c (is_friend): Fix access control for local classes. * class.c (is_empty_class): New fn. * call.c (build_call): Don't pass empty class objects to a function. From-SVN: r18933 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7d96732b377..8536976c06f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +Wed Apr 1 15:38:36 1998 Jason Merrill + + * friend.c (is_friend): Fix access control for local classes. + + * class.c (is_empty_class): New fn. + * call.c (build_call): Don't pass empty class objects to a function. + Wed Apr 1 14:58:35 1998 Mark Mitchell * call.c (build_over_call): Do name resolution for default diff --git a/gcc/cp/NEWS b/gcc/cp/NEWS index 82a75789d7c..ebfe3140075 100644 --- a/gcc/cp/NEWS +++ b/gcc/cp/NEWS @@ -1,9 +1,25 @@ *** Changes since EGCS 1.0: -* Template template parameters are now supported. +* Massive template improvements: + + member template classes are supported. + + template friends are supported. + + template template parameters are supported. + + local classes in templates are supported. + + lots of bugs fixed. * operator new now throws bad_alloc where appropriate. +* Exception handling is now thread safe, and supports nested + exceptions and placement delete. + +* protected virtual inheritance is now supported. + +* Loops are optimized better; we now move the test to the end in most + cases, like the C frontend does. + +* For class D derived from B which has a member 'int i', &D::i is now of + type 'int B::*' instead of 'int D::*'. + *** Changes in EGCS 1.0: * A public review copy of the December 1996 Draft of the ISO/ANSI C++ diff --git a/gcc/cp/call.c b/gcc/cp/call.c index ab3e05ef196..dc5957d1b88 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -24,11 +24,12 @@ Boston, MA 02111-1307, USA. */ /* High-level class interface. */ #include "config.h" -#include "tree.h" #include "system.h" +#include "tree.h" #include "cp-tree.h" #include "output.h" #include "flags.h" +#include "rtl.h" #include "obstack.h" #define obstack_chunk_alloc xmalloc @@ -492,6 +493,7 @@ build_call (function, result_type, parms) tree function, result_type, parms; { int is_constructor = 0; + tree tmp; function = build_addr_func (function); @@ -506,6 +508,20 @@ build_call (function, result_type, parms) && DECL_CONSTRUCTOR_P (TREE_OPERAND (function, 0))) is_constructor = 1; + /* Don't actually pass empty class objects to a function. This is useful + for tags in STL, which are used to control overload resolution. + We don't need to handle other cases of copying empty classes. */ + for (tmp = parms; tmp; tmp = TREE_CHAIN (tmp)) + if (is_empty_class (TREE_TYPE (TREE_VALUE (tmp))) + && ! TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (tmp)))) + { + tree t = make_node (RTL_EXPR); + TREE_TYPE (t) = TREE_TYPE (TREE_VALUE (tmp)); + RTL_EXPR_RTL (t) = const0_rtx; + RTL_EXPR_SEQUENCE (t) = NULL_RTX; + TREE_VALUE (tmp) = t; + } + function = build_nt (CALL_EXPR, function, parms, NULL_TREE); TREE_HAS_CONSTRUCTOR (function) = is_constructor; TREE_TYPE (function) = result_type; diff --git a/gcc/cp/class.c b/gcc/cp/class.c index d7251240d72..73701d2ee61 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5526,3 +5526,19 @@ build_self_reference () pushdecl_class_level (value); return value; } + +/* Returns 1 if TYPE contains only padding bytes. */ + +int +is_empty_class (type) + tree type; +{ + tree t; + + if (! IS_AGGR_TYPE (type) || TYPE_BINFO_BASETYPES (type)) + return 0; + t = TYPE_FIELDS (type); + while (t && TREE_CODE (t) != FIELD_DECL) + t = TREE_CHAIN (t); + return (t == NULL_TREE); +} diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c index b1f1285b3da..9a86ebc609c 100644 --- a/gcc/cp/friend.c +++ b/gcc/cp/friend.c @@ -44,15 +44,6 @@ is_friend (type, supplicant) declp = (TREE_CODE_CLASS (TREE_CODE (supplicant)) == 'd'); - /* Local classes have the same access as the enclosing function. */ - context = declp ? supplicant : TYPE_MAIN_DECL (supplicant); - context = hack_decl_function_context (context); - if (context) - { - supplicant = context; - declp = 1; - } - if (declp) /* It's a function decl. */ { @@ -121,8 +112,10 @@ is_friend (type, supplicant) if (declp && DECL_FUNCTION_MEMBER_P (supplicant)) context = DECL_CLASS_CONTEXT (supplicant); + else if (! declp) + /* Local classes have the same access as the enclosing function. */ + context = hack_decl_function_context (TYPE_MAIN_DECL (supplicant)); else - /* Nested classes don't inherit the access of their enclosing class. */ context = NULL_TREE; if (context)