friend.c (is_friend): Fix access control for local classes.
authorJason Merrill <jason@yorick.cygnus.com>
Wed, 1 Apr 1998 17:05:25 +0000 (17:05 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 1 Apr 1998 17:05:25 +0000 (12:05 -0500)
* 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

gcc/cp/ChangeLog
gcc/cp/NEWS
gcc/cp/call.c
gcc/cp/class.c
gcc/cp/friend.c

index 7d96732b377836897b1ed4e894a6317452535890..8536976c06f8f03fd81526857521def8c8b8a937 100644 (file)
@@ -1,3 +1,10 @@
+Wed Apr  1 15:38:36 1998  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * 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  <mmitchell@usa.net>
 
        * call.c (build_over_call): Do name resolution for default
index 82a75789d7c0440caa5616bcf0bd1e7c2b38ed66..ebfe3140075e57f3e303a2933f2419177abfc318 100644 (file)
@@ -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++
index ab3e05ef196d16bdf93c44e1415d93a50ee1355f..dc5957d1b887cdf3777dc17891ccebf7322cd10f 100644 (file)
@@ -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;
index d7251240d72197eac65cafd51ce62c4c70d20c0d..73701d2ee614daf54c4fa753c17f8220f8ed4cba 100644 (file)
@@ -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);
+}
index b1f1285b3da5999d2f16fd2cbc44d3ecae3a23b7..9a86ebc609c9e57d180979c6f99a28cc53970783 100644 (file)
@@ -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)