OSDN Git Service

PR c++/5296
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Sep 2003 16:53:05 +0000 (16:53 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Sep 2003 16:53:05 +0000 (16:53 +0000)
* pt.c (try_one_overload): Add addr_p parameter.
(resolve_overloaded_unification): Pass it.

PR c++/5296
* g++.dg/rtti/typeid2.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71209 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/rtti/typeid2.C [new file with mode: 0644]

index 9fea09b..b3a27e8 100644 (file)
@@ -1,3 +1,9 @@
+2003-09-08  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/5296
+       * pt.c (try_one_overload): Add addr_p parameter.
+       (resolve_overloaded_unification): Pass it.
+
 2003-09-08  Richard Henderson  <rth@redhat.com>
 
        * decl.c (finish_function): Clear current_function_decl.
index bb93047..f829095 100644 (file)
@@ -93,7 +93,7 @@ static void pop_access_scope (tree);
 static int resolve_overloaded_unification (tree, tree, tree, tree,
                                           unification_kind_t, int);
 static int try_one_overload (tree, tree, tree, tree, tree,
-                            unification_kind_t, int);
+                            unification_kind_t, int, bool);
 static int unify (tree, tree, tree, tree, int);
 static void add_pending_template (tree);
 static void reopen_tinst_level (tree);
@@ -8924,9 +8924,15 @@ resolve_overloaded_unification (tree tparms,
 {
   tree tempargs = copy_node (targs);
   int good = 0;
+  bool addr_p;
 
   if (TREE_CODE (arg) == ADDR_EXPR)
-    arg = TREE_OPERAND (arg, 0);
+    {
+      arg = TREE_OPERAND (arg, 0);
+      addr_p = true;
+    }
+  else
+    addr_p = false;
 
   if (TREE_CODE (arg) == COMPONENT_REF)
     /* Handle `&x' where `x' is some static or non-static member
@@ -8962,10 +8968,8 @@ resolve_overloaded_unification (tree tparms,
          if (subargs)
            {
              elem = tsubst (TREE_TYPE (fn), subargs, tf_none, NULL_TREE);
-             if (TREE_CODE (elem) == METHOD_TYPE)
-               elem = build_ptrmemfunc_type (build_pointer_type (elem));
-             good += try_one_overload (tparms, targs, tempargs, parm, elem,
-                                       strict, sub_strict);
+             good += try_one_overload (tparms, targs, tempargs, parm, 
+                                       elem, strict, sub_strict, addr_p);
            }
        }
     }
@@ -8973,14 +8977,9 @@ resolve_overloaded_unification (tree tparms,
           || TREE_CODE (arg) == FUNCTION_DECL)
     {
       for (; arg; arg = OVL_NEXT (arg))
-       {
-         tree type = TREE_TYPE (OVL_CURRENT (arg));
-         if (TREE_CODE (type) == METHOD_TYPE)
-           type = build_ptrmemfunc_type (build_pointer_type (type));
-         good += try_one_overload (tparms, targs, tempargs, parm,
-                                   type,
-                                   strict, sub_strict);
-       }
+       good += try_one_overload (tparms, targs, tempargs, parm,
+                                 TREE_TYPE (OVL_CURRENT (arg)),
+                                 strict, sub_strict, addr_p);
     }
   else
     abort ();
@@ -9009,6 +9008,9 @@ resolve_overloaded_unification (tree tparms,
 /* Subroutine of resolve_overloaded_unification; does deduction for a single
    overload.  Fills TARGS with any deduced arguments, or error_mark_node if
    different overloads deduce different arguments for a given parm.
+   ADDR_P is true if the expression for which deduction is being
+   performed was of the form "& fn" rather than simply "fn".
+
    Returns 1 on success.  */
 
 static int
@@ -9018,7 +9020,8 @@ try_one_overload (tree tparms,
                   tree parm, 
                   tree arg, 
                   unification_kind_t strict,
-                 int sub_strict)
+                 int sub_strict,
+                 bool addr_p)
 {
   int nargs;
   tree tempargs;
@@ -9034,6 +9037,11 @@ try_one_overload (tree tparms,
   if (uses_template_parms (arg))
     return 1;
 
+  if (TREE_CODE (arg) == METHOD_TYPE)
+    arg = build_ptrmemfunc_type (build_pointer_type (arg));
+  else if (addr_p)
+    arg = build_pointer_type (arg);
+
   sub_strict |= maybe_adjust_types_for_deduction (strict, &parm, &arg);
 
   /* We don't copy orig_targs for this because if we have already deduced
index 032e090..bf04edf 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-08  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/5296
+       * g++.dg/rtti/typeid2.C: New test.
+
 2003-09-08  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c-torture/compile/20030904-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/rtti/typeid2.C b/gcc/testsuite/g++.dg/rtti/typeid2.C
new file mode 100644 (file)
index 0000000..0dbcc59
--- /dev/null
@@ -0,0 +1,15 @@
+// { dg-do run }
+
+#include <typeinfo>
+
+template <typename T>  const char *print_type (const T &) {
+  return typeid(T).name();
+}
+
+/* no template */      void pp1 (int) {}
+template <typename X>  void pp2 (X)   {}
+
+int main () {
+  if (print_type (&pp1) != print_type (&pp2<int>))
+    return 1;
+}