aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2009-11-19 11:59:05 -0500
committerJason Merrill <jason@gcc.gnu.org>2009-11-19 11:59:05 -0500
commit7bead48f160d4faab372aeab8a5200c5c21d2523 (patch)
tree918b5da9a9ebc906d543b57fb0a5e50e3dd5076f /gcc/cp/class.c
parent4a85780b75143fa28bc26ce508eafa95c5f5b3e8 (diff)
downloadgcc-7bead48f160d4faab372aeab8a5200c5c21d2523.zip
gcc-7bead48f160d4faab372aeab8a5200c5c21d2523.tar.gz
gcc-7bead48f160d4faab372aeab8a5200c5c21d2523.tar.bz2
re PR c++/561 (std:unclear about Overloaded Function Pointer resolution)
PR c++/561 * decl.c (static_fn_type): Split out... (revert_static_member_fn): ...from here. * cp-tree.h: Declare it. * class.c (resolve_address_of_overloaded_function): Use it to compare pointers to member functions. * typeck.c (build_static_cast_1): Call instantiate_type. From-SVN: r154336
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index c798ba2..3cf15fb 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -6065,6 +6065,7 @@ resolve_address_of_overloaded_function (tree target_type,
interoperability with most_specialized_instantiation. */
tree matches = NULL_TREE;
tree fn;
+ tree target_fn_type;
/* By the time we get here, we should be seeing only real
pointer-to-member types, not the internal POINTER_TYPE to
@@ -6096,6 +6097,15 @@ resolve_address_of_overloaded_function (tree target_type,
return error_mark_node;
}
+ /* Non-member functions and static member functions match targets of type
+ "pointer-to-function" or "reference-to-function." Nonstatic member
+ functions match targets of type "pointer-to-member-function;" the
+ function type of the pointer to member is used to select the member
+ function from the set of overloaded member functions.
+
+ So figure out the FUNCTION_TYPE that we want to match against. */
+ target_fn_type = static_fn_type (target_type);
+
/* If we can find a non-template function that matches, we can just
use it. There's no point in generating template instantiations
if we're just going to throw them out anyhow. But, of course, we
@@ -6107,7 +6117,6 @@ resolve_address_of_overloaded_function (tree target_type,
for (fns = overload; fns; fns = OVL_NEXT (fns))
{
tree fn = OVL_CURRENT (fns);
- tree fntype;
if (TREE_CODE (fn) == TEMPLATE_DECL)
/* We're not looking for templates just yet. */
@@ -6125,13 +6134,7 @@ resolve_address_of_overloaded_function (tree target_type,
continue;
/* See if there's a match. */
- fntype = TREE_TYPE (fn);
- if (is_ptrmem)
- fntype = build_ptrmemfunc_type (build_pointer_type (fntype));
- else if (!is_reference)
- fntype = build_pointer_type (fntype);
-
- if (can_convert_arg (target_type, fntype, fn, LOOKUP_NORMAL))
+ if (same_type_p (target_fn_type, static_fn_type (fn)))
matches = tree_cons (fn, NULL_TREE, matches);
}
}
@@ -6141,7 +6144,6 @@ resolve_address_of_overloaded_function (tree target_type,
match we need to look at them, too. */
if (!matches)
{
- tree target_fn_type;
tree target_arg_types;
tree target_ret_type;
tree fns;
@@ -6149,18 +6151,9 @@ resolve_address_of_overloaded_function (tree target_type,
unsigned int nargs, ia;
tree arg;
- if (is_ptrmem)
- target_fn_type
- = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type));
- else
- target_fn_type = TREE_TYPE (target_type);
target_arg_types = TYPE_ARG_TYPES (target_fn_type);
target_ret_type = TREE_TYPE (target_fn_type);
- /* Never do unification on the 'this' parameter. */
- if (TREE_CODE (target_fn_type) == METHOD_TYPE)
- target_arg_types = TREE_CHAIN (target_arg_types);
-
nargs = list_length (target_arg_types);
args = XALLOCAVEC (tree, nargs);
for (arg = target_arg_types, ia = 0;
@@ -6173,7 +6166,6 @@ resolve_address_of_overloaded_function (tree target_type,
{
tree fn = OVL_CURRENT (fns);
tree instantiation;
- tree instantiation_type;
tree targs;
if (TREE_CODE (fn) != TEMPLATE_DECL)
@@ -6201,14 +6193,7 @@ resolve_address_of_overloaded_function (tree target_type,
continue;
/* See if there's a match. */
- instantiation_type = TREE_TYPE (instantiation);
- if (is_ptrmem)
- instantiation_type =
- build_ptrmemfunc_type (build_pointer_type (instantiation_type));
- else if (!is_reference)
- instantiation_type = build_pointer_type (instantiation_type);
- if (can_convert_arg (target_type, instantiation_type, instantiation,
- LOOKUP_NORMAL))
+ if (same_type_p (target_fn_type, static_fn_type (instantiation)))
matches = tree_cons (instantiation, fn, matches);
}