diff options
author | Mark Mitchell <mark@codesourcery.com> | 2003-09-08 16:53:05 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2003-09-08 16:53:05 +0000 |
commit | f23fb7f5252c3cb2f551d66c0887e2232f10736d (patch) | |
tree | 7ad79d8a9b99c0035eca8e5d90faf2985d09d4b4 | |
parent | c1f927e84ec73debafbc0114cc4d81abd1b27ae7 (diff) | |
download | gcc-f23fb7f5252c3cb2f551d66c0887e2232f10736d.zip gcc-f23fb7f5252c3cb2f551d66c0887e2232f10736d.tar.gz gcc-f23fb7f5252c3cb2f551d66c0887e2232f10736d.tar.bz2 |
re PR c++/5296 ([DR115] Pointers to functions and template functions behave different in deduction)
PR c++/5296
* pt.c (try_one_overload): Add addr_p parameter.
(resolve_overloaded_unification): Pass it.
PR c++/5296
* g++.dg/rtti/typeid2.C: New test.
From-SVN: r71209
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/pt.c | 38 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/rtti/typeid2.C | 15 |
4 files changed, 49 insertions, 15 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9fea09b..b3a27e8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bb93047..f829095 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 032e090..bf04edf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..0dbcc59 --- /dev/null +++ b/gcc/testsuite/g++.dg/rtti/typeid2.C @@ -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; +} |