call.c (enforce_access): Assert we get a binfo.
authorNathan Sidwell <nathan@gcc.gnu.org>
Tue, 24 Jun 2003 15:40:06 +0000 (15:40 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 24 Jun 2003 15:40:06 +0000 (15:40 +0000)
* call.c (enforce_access): Assert we get a binfo.
(build_op_delete_call): Pass a binfo to
perform_or_defer_access_check.
* class.c (alter_access): Likewise.
* decl.c (make_typename_type): Likewise.
(make_unbound_class_template): Likewise.
* lex.c (do_identifier): Likewise.
* method.c (hack_identifier): Likewise.
* parser.c (cp_parser_lookup_name): Likewise.
* search.c (lookup_member): Likewise. Move IDENTIFIER_CLASS_VALUE
test.
* semantics.c (finish_non_static_data_member): Likewise.
(perform_or_defer_access_check): Expect a binfo.
* typeck.c (comptypes): Expect types.

* mangle.c (find_substitution): Don't pass a non-type to same_type_p
* friend.c (make_friend_class): Likewise.
* pt.c (check_default_tmpl_args): Likewise.
(lookup_template_class): Likewise.

From-SVN: r68424

13 files changed:
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/class.c
gcc/cp/decl.c
gcc/cp/friend.c
gcc/cp/lex.c
gcc/cp/mangle.c
gcc/cp/method.c
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/search.c
gcc/cp/semantics.c
gcc/cp/typeck.c

index 8ae7c023e9a4aaf46b49b83c64be6b50183bf897..65ca03d9e563e9bca9d06b37eb15db04a1202636 100644 (file)
@@ -1,3 +1,25 @@
+2003-06-24  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * call.c (enforce_access): Assert we get a binfo.
+       (build_op_delete_call): Pass a binfo to
+       perform_or_defer_access_check.
+       * class.c (alter_access): Likewise.
+       * decl.c (make_typename_type): Likewise.
+       (make_unbound_class_template): Likewise.
+       * lex.c (do_identifier): Likewise.
+       * method.c (hack_identifier): Likewise.
+       * parser.c (cp_parser_lookup_name): Likewise.
+       * search.c (lookup_member): Likewise. Move IDENTIFIER_CLASS_VALUE
+       test.
+       * semantics.c (finish_non_static_data_member): Likewise.
+       (perform_or_defer_access_check): Expect a binfo.
+       * typeck.c (comptypes): Expect types.
+
+       * mangle.c (find_substitution): Don't pass a non-type to same_type_p
+       * friend.c (make_friend_class): Likewise.
+       * pt.c (check_default_tmpl_args): Likewise.
+       (lookup_template_class): Likewise.
+
 Tue Jun 24 15:30:05 CEST 2003  Jan Hubicka  <jh@suse.cz>
 
        * method.c (thunk_labelno): Move outside ifdef block to make garbage
@@ -41,7 +63,7 @@ Mon Jun 23 19:41:27 CEST 2003  Jan Hubicka  <jh@suse.cz>
 
 2003-06-23  Jakub Jelinek  <jakub@redhat.com>
 
-       * mangle.c (hash_type): val is the TREE_LIST itself, not a pointer
+       * mangle.c (hash_type): Val is the TREE_LIST itself, not a pointer
        to it.
 
 2003-06-21  Gabriel Dos Reis <gdr@integrable-solutions.net>
index bb1ad5b91bce2bdb76da509e31c241850bbe1f7a..77ed3e8686ff31ff90d43b698c9633087a681512 100644 (file)
@@ -4071,7 +4071,7 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
       /* If the FN is a member function, make sure that it is
         accessible.  */
       if (DECL_CLASS_SCOPE_P (fn))
-       perform_or_defer_access_check (type, fn);
+       perform_or_defer_access_check (TYPE_BINFO (type), fn);
 
       if (pass == 0)
        args = tree_cons (NULL_TREE, addr, args);
@@ -4098,6 +4098,8 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
 bool
 enforce_access (tree basetype_path, tree decl)
 {
+  my_friendly_assert (TREE_CODE (basetype_path) == TREE_VEC, 20030624);
+  
   if (!accessible_p (basetype_path, decl))
     {
       if (TREE_PRIVATE (decl))
index 12c206854564c40a1df5c5fa804b1e2a63fc1b13..b5eb245f4f298dc1d580c332eede371f11dffe12 100644 (file)
@@ -1064,8 +1064,7 @@ alter_access (tree t, tree fdecl, tree access)
   if (!DECL_LANG_SPECIFIC (fdecl))
     retrofit_lang_decl (fdecl);
 
-  if (DECL_DISCRIMINATOR_P (fdecl))
-    abort ();
+  my_friendly_assert (!DECL_DISCRIMINATOR_P (fdecl), 20030624);
 
   elem = purpose_member (t, DECL_ACCESS (fdecl));
   if (elem)
@@ -1087,7 +1086,7 @@ alter_access (tree t, tree fdecl, tree access)
     }
   else
     {
-      perform_or_defer_access_check (t, fdecl);
+      perform_or_defer_access_check (TYPE_BINFO (t), fdecl);
       DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
       return 1;
     }
index 9e3a9ce9957e3c32a2caf9e4c05350a92a0eac0d..b9c59af6cc72b4f8c58bb53ddf9c6d5fe135d091 100644 (file)
@@ -5525,7 +5525,7 @@ make_typename_type (tree context, tree name, tsubst_flags_t complain)
            }
 
          if (complain & tf_error)
-           perform_or_defer_access_check (context, tmpl);
+           perform_or_defer_access_check (TYPE_BINFO (context), tmpl);
 
          return lookup_template_class (tmpl,
                                        TREE_OPERAND (fullname, 1),
@@ -5555,7 +5555,7 @@ make_typename_type (tree context, tree name, tsubst_flags_t complain)
                }
 
              if (complain & tf_error)
-               perform_or_defer_access_check (context, t);
+               perform_or_defer_access_check (TYPE_BINFO (context), t);
 
              if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
                t = TREE_TYPE (t);
@@ -5612,7 +5612,7 @@ make_unbound_class_template (tree context, tree name, tsubst_flags_t complain)
        }
       
       if (complain & tf_error)
-       perform_or_defer_access_check (context, tmpl);
+       perform_or_defer_access_check (TYPE_BINFO (context), tmpl);
 
       return tmpl;
     }
index 3ecd3177195a509a4f4a1140e1cb092a91c72520..0a0e82c7fcdbd522c7f18337b2c080e69c1ad541 100644 (file)
@@ -264,17 +264,34 @@ make_friend_class (type, friend_type)
   if (is_template_friend)
     friend_type = CLASSTYPE_TI_TEMPLATE (friend_type);
 
-  classes = CLASSTYPE_FRIEND_CLASSES (type);
-  while (classes 
-        /* Stop if we find the same type on the list.  */
-        && !(TREE_CODE (TREE_VALUE (classes)) == TEMPLATE_DECL ?
-             friend_type == TREE_VALUE (classes) :
-             same_type_p (TREE_VALUE (classes), friend_type)))
-    classes = TREE_CHAIN (classes);
-  if (classes) 
-    warning ("`%T' is already a friend of `%T'",
-               TREE_VALUE (classes), type);
-  else
+  /* See if it is already a friend.  */
+  for (classes = CLASSTYPE_FRIEND_CLASSES (type);
+       classes;
+       classes = TREE_CHAIN (classes))
+    {
+      tree probe = TREE_VALUE (classes);
+
+      if (TREE_CODE (friend_type) == TEMPLATE_DECL)
+       {
+         if (friend_type == probe)
+           {
+             warning ("`%D' is already a friend of `%T'",
+                      probe, type);
+             break;
+           }
+       }
+      else if (TREE_CODE (probe) != TEMPLATE_DECL)
+       {
+         if (same_type_p (probe, friend_type))
+           {
+             warning ("`%T' is already a friend of `%T'",
+                      probe, type);
+             break;
+           }
+       }
+    }
+  
+  if (!classes) 
     {
       maybe_add_class_template_decl_list (type, friend_type, /*friend_p=*/1);
 
index 1f8cb0672a39aaf1953ffecb815773e0fc54417b..b378dc1724a64418be5e53ce4a1e06a2646e0550 100644 (file)
@@ -777,7 +777,7 @@ do_identifier (register tree token, tree args)
     {
       /* Check access.  */
       if (IDENTIFIER_CLASS_VALUE (token) == id)
-       perform_or_defer_access_check (CP_DECL_CONTEXT(id), id);
+       perform_or_defer_access_check (TYPE_BINFO (DECL_CONTEXT (id)), id);
       if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
        id = DECL_INITIAL (id);
     }
index e4c75b473c6b1c1f590098752071f098a55de65f..b5d0a645af492f749451c1c47db2ff02f055e001 100644 (file)
@@ -546,6 +546,7 @@ find_substitution (tree node)
         args <char, std::char_traits<char> > .  */
       tree args = CLASSTYPE_TI_ARGS (type);
       if (TREE_VEC_LENGTH (args) == 2
+         && TYPE_P (TREE_VEC_ELT (args, 0))
          && same_type_p (TREE_VEC_ELT (args, 0), char_type_node)
          && is_std_substitution_char (TREE_VEC_ELT (args, 1),
                                       SUBID_CHAR_TRAITS))
index d02d0243f87d845d18e12de5806ee2af0a17701a..cb2c864bfca89428c9ea50a8e24a3115f98cd3d7 100644 (file)
@@ -182,7 +182,7 @@ hack_identifier (tree value, tree name)
        {
          tree path;
          path = currently_open_derived_class (DECL_CONTEXT (value));
-         perform_or_defer_access_check (path, value);
+         perform_or_defer_access_check (TYPE_BINFO (path), value);
        }
     }
   else if (TREE_CODE (value) == TREE_LIST 
index 4799944b99481c86dcefbe436e91ceecd2e14207..6240c244607a5c1805b796046e95acf2c677f7eb 100644 (file)
@@ -13353,7 +13353,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
                                                       object_type,
                                                       parser->scope);
       if (qualifying_type)
-       perform_or_defer_access_check (qualifying_type, decl);
+       perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl);
     }
 
   return decl;
index 7ce9031e03335d30011f92dfe3a30b7809f6b56a..e29d434c00097d8c5d999b3dee945b91a67945ce 100644 (file)
@@ -2528,14 +2528,15 @@ check_default_tmpl_args (tree decl, tree parms, int is_primary, int is_partial)
       && DECL_LANG_SPECIFIC (decl)
       /* If this is either a friend defined in the scope of the class
         or a member function.  */
-      && ((DECL_CONTEXT (decl) 
-          && same_type_p (DECL_CONTEXT (decl), current_class_type))
-         || (DECL_FRIEND_CONTEXT (decl)
-             && same_type_p (DECL_FRIEND_CONTEXT (decl), 
-                             current_class_type)))
+      && (DECL_FUNCTION_MEMBER_P (decl)
+         ? same_type_p (DECL_CONTEXT (decl), current_class_type)
+         DECL_FRIEND_CONTEXT (decl)
+         ? same_type_p (DECL_FRIEND_CONTEXT (decl), current_class_type)
+         : false)
       /* And, if it was a member function, it really was defined in
         the scope of the class.  */
-      && (!DECL_FUNCTION_MEMBER_P (decl) || DECL_INITIALIZED_IN_CLASS_P (decl)))
+      && (!DECL_FUNCTION_MEMBER_P (decl)
+         || DECL_INITIALIZED_IN_CLASS_P (decl)))
     /* We already checked these parameters when the template was
        declared, so there's no need to do it again now.  This function
        was defined in class scope, but we're processing it's body now
@@ -4234,21 +4235,20 @@ lookup_template_class (tree d1,
            {
              tree ctx;
              
-             /* Note that we use DECL_CONTEXT, rather than
-                CP_DECL_CONTEXT, so that the termination test is
-                always just `ctx'.  We're not interested in namespace
-                scopes.  */
              for (ctx = current_class_type; 
                   ctx; 
-                  ctx = (TYPE_P (ctx)) ? TYPE_CONTEXT (ctx) : DECL_CONTEXT (ctx))
-               if (same_type_p (ctx, template_type))
-                 break;
+                  ctx = TYPE_CONTEXT (ctx))
+               {
+                 if (TREE_CODE (ctx) == NAMESPACE_DECL)
+                   break;
+                 if (same_type_p (ctx, template_type))
+                   goto found_ctx;
+               }
              
-             if (!ctx)
-               /* We're not in the scope of the class, so the
-                  TEMPLATE_TYPE is not the type we want after
-                  all.  */
-               found = NULL_TREE;
+             /* We're not in the scope of the class, so the
+                TEMPLATE_TYPE is not the type we want after all.  */
+             found = NULL_TREE;
+           found_ctx:;
            }
        }
       if (found)
index 3df6f733f74c01bd45674239499bf9b50b0b077d..a853c208bdf586e5a2998e28ca6e30fc32344e8d 100644 (file)
@@ -1226,35 +1226,31 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type)
 
   const char *errstr = 0;
 
-  /* Sanity check.  */
-  if (TREE_CODE (name) != IDENTIFIER_NODE)
-    abort ();
-
-  if (xbasetype == current_class_type && TYPE_BEING_DEFINED (xbasetype)
-      && IDENTIFIER_CLASS_VALUE (name))
-    {
-      tree field = IDENTIFIER_CLASS_VALUE (name);
-      if (! is_overloaded_fn (field)
-         && ! (want_type && TREE_CODE (field) != TYPE_DECL))
-       /* We're in the scope of this class, and the value has already
-          been looked up.  Just return the cached value.  */
-       return field;
-    }
+  my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 20030624);
 
   if (TREE_CODE (xbasetype) == TREE_VEC)
     {
       type = BINFO_TYPE (xbasetype);
       basetype_path = xbasetype;
     }
-  else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)))
+  else
     {
+      my_friendly_assert (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)), 20030624);
       type = xbasetype;
       basetype_path = TYPE_BINFO (type);
-      my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path) == NULL_TREE,
-                         980827);
+      my_friendly_assert (!BINFO_INHERITANCE_CHAIN (basetype_path), 980827);
+    }
+
+  if (type == current_class_type && TYPE_BEING_DEFINED (type)
+      && IDENTIFIER_CLASS_VALUE (name))
+    {
+      tree field = IDENTIFIER_CLASS_VALUE (name);
+      if (! is_overloaded_fn (field)
+         && ! (want_type && TREE_CODE (field) != TYPE_DECL))
+       /* We're in the scope of this class, and the value has already
+          been looked up.  Just return the cached value.  */
+       return field;
     }
-  else
-    abort ();
 
   complete_type (type);
 
@@ -1291,7 +1287,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type)
      In the case of overloaded function names, access control is
      applied to the function selected by overloaded resolution.  */
   if (rval && protect && !is_overloaded_fn (rval))
-    perform_or_defer_access_check (xbasetype, rval);
+    perform_or_defer_access_check (basetype_path, rval);
 
   if (errstr && protect)
     {
index bb55b75af88b592e754d9ff52760a88bc9fd51d2..3272284d9c7a5f098f1da05d3e1f035ac46822e5 100644 (file)
@@ -262,16 +262,18 @@ void perform_deferred_access_checks (void)
 }
 
 /* Defer checking the accessibility of DECL, when looked up in
-   CLASS_TYPE.  */
+   BINFO.  */
 
-void perform_or_defer_access_check (tree class_type, tree decl)
+void perform_or_defer_access_check (tree binfo, tree decl)
 {
   tree check;
 
+  my_friendly_assert (TREE_CODE (binfo) == TREE_VEC, 20030623);
+  
   /* If we are not supposed to defer access checks, just check now.  */
   if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred)
     {
-      enforce_access (class_type, decl);
+      enforce_access (binfo, decl);
       return;
     }
   /* Exit if we are in a context that no access checking is performed.  */
@@ -282,13 +284,11 @@ void perform_or_defer_access_check (tree class_type, tree decl)
   for (check = deferred_access_stack->deferred_access_checks;
        check;
        check = TREE_CHAIN (check))
-    if (TREE_VALUE (check) == decl
-       && TYPE_P (TREE_PURPOSE (check))
-       && same_type_p (TREE_PURPOSE (check), class_type))
+    if (TREE_VALUE (check) == decl && TREE_PURPOSE (check) == binfo)
       return;
   /* If not, record the check.  */
   deferred_access_stack->deferred_access_checks
-    = tree_cons (class_type, decl,
+    = tree_cons (binfo, decl,
                 deferred_access_stack->deferred_access_checks);
 }
 
@@ -1255,7 +1255,7 @@ finish_non_static_data_member (tree decl, tree qualifying_scope)
          return error_mark_node;
        }
 
-      perform_or_defer_access_check (access_type, decl);
+      perform_or_defer_access_check (TYPE_BINFO (access_type), decl);
 
       /* If the data member was named `C::M', convert `*this' to `C'
         first.  */
index c80ca6b44d04e831e572020cf22d0eb1e42ec05a..be53d45154593c2923c00e6cbad5614c84ceeb79 100644 (file)
@@ -883,7 +883,9 @@ comptypes (tree t1, tree t2, int strict)
   /* Suppress errors caused by previously reported errors */
   if (t2 == error_mark_node)
     return false;
-
+  
+  my_friendly_assert (TYPE_P (t1) && TYPE_P (t2), 20030623);
+  
   /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
      current instantiation.  */
   if (TREE_CODE (t1) == TYPENAME_TYPE)