call.c (add_function_candidate): Treat conversion functions as coming from the argume...
authorJason Merrill <jason@yorick.cygnus.com>
Wed, 28 Oct 1998 01:53:50 +0000 (01:53 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 28 Oct 1998 01:53:50 +0000 (20:53 -0500)
* call.c (add_function_candidate): Treat conversion functions
as coming from the argument's class.
* cp-tree.h (DECL_CONV_FN_P): New fn.
(DECL_DESTRUCTOR_P): Also check DECL_LANGUAGE.
* class.c (add_method): Use DECL_CONV_FN_P.
* decl2.c (check_classfn): Likewise.
* error.c (dump_function_name): Likewise.
(dump_function_decl): Likewise.
* pt.c (fn_type_unification): Likewise.
* search.c (add_conversions): Likewise.

From-SVN: r23387

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/cp/error.c
gcc/cp/pt.c
gcc/cp/search.c

index 328039aaec25da7b4e7b9f30ae2f7bb5165f50d7..b47514b0563fb49c5c840141e0bf107672ba253c 100644 (file)
@@ -1,3 +1,16 @@
+1998-10-28  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * call.c (add_function_candidate): Treat conversion functions
+       as coming from the argument's class.
+       * cp-tree.h (DECL_CONV_FN_P): New fn.
+       (DECL_DESTRUCTOR_P): Also check DECL_LANGUAGE.
+       * class.c (add_method): Use DECL_CONV_FN_P.
+       * decl2.c (check_classfn): Likewise.
+       * error.c (dump_function_name): Likewise.
+       (dump_function_decl): Likewise.
+       * pt.c (fn_type_unification): Likewise.
+       * search.c (add_conversions): Likewise.
+
 1998-10-27  Jason Merrill  <jason@yorick.cygnus.com>
 
        * lex.c (do_identifier): Also generate LOOKUP_EXPR for RESULT_DECL.
index 8e074b6d9c9453ca82706c3a02f3b5fd6e824f86..37847845b37042dfee178df5ba9c394ceefe2846 100644 (file)
@@ -1150,8 +1150,28 @@ add_function_candidate (candidates, fn, arglist, flags)
 
       if (parmnode == void_list_node)
        break;
-      else if (parmnode)
-       t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg, flags);
+
+      if (parmnode)
+       {
+         tree parmtype = TREE_VALUE (parmnode);
+
+         /* [over.match.funcs] For conversion functions, the function is
+            considered to be a member of the class of the implicit object
+            argument for the purpose of defining the type of the implicit
+            object parameter.
+
+            Since build_over_call ignores the ICS for the `this' parameter,
+            we can just change the parm type.  */
+         if (DECL_CONV_FN_P (fn) && i == 0)
+           {
+             parmtype
+               = build_qualified_type (TREE_TYPE (argtype),
+                                       TYPE_QUALS (TREE_TYPE (parmtype)));
+             parmtype = build_pointer_type (parmtype);
+           }
+
+         t = implicit_conversion (parmtype, argtype, arg, flags);
+       }
       else
        {
          t = build1 (IDENTITY_CONV, argtype, arg);
index c5d67e57ed52651df833150a1e17f68168e1c73e..9180e64c9e4f82eb500ecfdd4cce12a1fabc4912 100644 (file)
@@ -1229,7 +1229,7 @@ add_method (type, fields, method)
                }
            }
 
-         if (IDENTIFIER_TYPENAME_P (DECL_NAME (method)))
+         if (DECL_CONV_FN_P (method))
            {
              /* Type conversion operators have to come before
                 ordinary methods; add_conversions depends on this to
@@ -1240,15 +1240,13 @@ add_method (type, fields, method)
              for (i = 2; i < len; ++i)
                {
                  tree fn = TREE_VEC_ELT (method_vec, i);
-                 tree name;
 
                  if (!fn)
                    /* There are no more entries in the vector, so we
                       can insert the new conversion operator here.  */
                    break;
                  
-                 name = DECL_NAME (OVL_CURRENT (fn));
-                 if (!IDENTIFIER_TYPENAME_P (name))
+                 if (! DECL_CONV_FN_P (OVL_CURRENT (fn)))
                    /* We can insert the new function right at the Ith
                       position.  */
                    break;
index b96246a9385342f04b40e78ab3c77cf2f3530842..61593d58dfee361e85f5cba133114a3aa53a4ddc 100644 (file)
@@ -1128,7 +1128,15 @@ struct lang_decl
 
 /* For FUNCTION_DECLs: nonzero means that this function is a constructor.  */
 #define DECL_CONSTRUCTOR_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.constructor_attr)
-#define DECL_DESTRUCTOR_P(NODE) (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME(NODE)))
+
+/* There ought to be a better way to find out whether or not something is
+   a destructor.  */
+#define DECL_DESTRUCTOR_P(NODE)                                \
+  (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (NODE))      \
+   && DECL_LANGUAGE (NODE) == lang_cplusplus)
+
+#define DECL_CONV_FN_P(NODE)                                                \
+  (IDENTIFIER_TYPENAME_P (DECL_NAME (NODE)) && TREE_TYPE (DECL_NAME (NODE)))
 
 /* For FUNCTION_DECLs: nonzero means that this function is a constructor
    for an object with virtual baseclasses.  */
index 6ef3099332db25f0dbc7ccd168413623b204f0d2..b16eb04648c0af8f8b486344add133ca1a309303 100644 (file)
@@ -1426,8 +1426,8 @@ check_classfn (ctype, function)
              break;            /* loser */
            }
          else if (TREE_CODE (fndecl) == TEMPLATE_DECL 
-                  && IDENTIFIER_TYPENAME_P (DECL_NAME (fndecl))
-                  && IDENTIFIER_TYPENAME_P (fn_name))
+                  && DECL_CONV_FN_P (fndecl)
+                  && DECL_CONV_FN_P (function))
            /* The method in the class is a member template
               conversion operator.  We are declaring another
               conversion operator.  It is possible that even though
index bd7d178879eb39a3695ae0e576fd2dc7d4981ccf..13469c0e1eaf999d166bd4dcc959042b1798ce2b 100644 (file)
@@ -978,9 +978,9 @@ dump_function_decl (t, v)
       if (DECL_STATIC_FUNCTION_P (t))
        OB_PUTS ("static ");
     
-      if (! IDENTIFIER_TYPENAME_P (name)
+      if (! DECL_CONV_FN_P (t)
          && ! DECL_CONSTRUCTOR_P (t)
-         && ! DESTRUCTOR_NAME_P (name))
+         && ! DECL_DESTRUCTOR_P (t))
        {
          dump_type_prefix (TREE_TYPE (fntype), 1, 0);
          OB_PUTC (' ');
@@ -1012,7 +1012,7 @@ dump_function_decl (t, v)
 
   OB_PUTC (')');
 
-  if (v && ! IDENTIFIER_TYPENAME_P (name))
+  if (v && ! DECL_CONV_FN_P (t))
     dump_type_suffix (TREE_TYPE (fntype), 1, 0);
 
   if (TREE_CODE (fntype) == METHOD_TYPE)
@@ -1036,15 +1036,12 @@ dump_function_name (t)
 {
   tree name = DECL_NAME (t);
 
-  /* There ought to be a better way to find out whether or not something is
-     a destructor.  */
-  if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t))
-      && DECL_LANGUAGE (t) == lang_cplusplus)
+  if (DECL_DESTRUCTOR_P (t))
     {
       OB_PUTC ('~');
       dump_decl (name, 0);
     }
-  else if (IDENTIFIER_TYPENAME_P (name))
+  else if (DECL_CONV_FN_P (t))
     {
       /* This cannot use the hack that the operator's return
         type is stashed off of its name because it may be
index 1efbd19ebfdd3300d4988ac9acd339ebdfcf3bc5..c0726b74e9ab355a277132227578f148b861d75a 100644 (file)
@@ -6565,7 +6565,7 @@ fn_type_unification (fn, explicit_targs, targs, args, return_type,
 
   parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
 
-  if (IDENTIFIER_TYPENAME_P (DECL_NAME (fn))) 
+  if (DECL_CONV_FN_P (fn))
     {
       /* This is a template conversion operator.  Use the return types
          as well as the argument types.  */
index c49fd2268d49df4f6209ee5ae5c326cd7b34bfb8..26599f12ec0383717210707a602b43540eac3673 100644 (file)
@@ -3295,8 +3295,7 @@ add_conversions (binfo)
     {
       tree tmp = TREE_VEC_ELT (method_vec, i);
 
-      if (!tmp
-         || !IDENTIFIER_TYPENAME_P (DECL_NAME (OVL_CURRENT (tmp))))
+      if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
        break;
       conversions = scratch_tree_cons (binfo, tmp, conversions);
     }