summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2007-07-07 07:31:54 +0000
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2007-07-07 07:31:54 +0000
commit9788fee1c2448852af5d37eac5ed4f88e1f43352 (patch)
treebca463c42618d10c0ca30ba315e4729c03478151 /gcc
parent70ae6476fa55847f2c1422691a16c8d405efa002 (diff)
downloadgcc-9788fee1c2448852af5d37eac5ed4f88e1f43352.tar.gz
PR c++/32232
* pt.c (resolve_overloaded_unification): Robustify. Return a bool, not an int. (type_unification_real): Adjust accordingly. PR c++/32232 * g++.dg/template/overload9.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126435 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/pt.c57
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/template/overload9.C18
4 files changed, 60 insertions, 27 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f22d5b7f429..2526a43ff03 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2007-07-07 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/32232
+ * pt.c (resolve_overloaded_unification): Robustify. Return a
+ bool, not an int.
+ (type_unification_real): Adjust accordingly.
+
2007-07-06 Richard Guenther <rguenther@suse.de>
* init.c (build_new_1): Use the correct pointer type.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b822d951463..06e94e74fdb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -97,8 +97,8 @@ static GTY(()) VEC(tree,gc) *canonical_template_parms;
static void push_access_scope (tree);
static void pop_access_scope (tree);
-static int resolve_overloaded_unification (tree, tree, tree, tree,
- unification_kind_t, int);
+static bool 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, bool);
static int unify (tree, tree, tree, tree, int);
@@ -11471,17 +11471,18 @@ type_unification_real (tree tparms,
gcc_assert (TREE_TYPE (arg) != NULL_TREE);
if (type_unknown_p (arg))
{
- /* [temp.deduct.type] A template-argument can be deduced from
- a pointer to function or pointer to member function
- argument if the set of overloaded functions does not
- contain function templates and at most one of a set of
- overloaded functions provides a unique match. */
+ /* [temp.deduct.type]
+ A template-argument can be deduced from a pointer to
+ function or pointer to member function argument if
+ the set of overloaded functions does not contain
+ function templates and at most one of a set of
+ overloaded functions provides a unique match. */
if (resolve_overloaded_unification
- (tparms, targs, parm, arg, strict, sub_strict)
- != 0)
- return 1;
- continue;
+ (tparms, targs, parm, arg, strict, sub_strict))
+ continue;
+
+ return 1;
}
arg_expr = arg;
arg = unlowered_expr_type (arg);
@@ -11611,12 +11612,13 @@ type_unification_real (tree tparms,
return 0;
}
-/* Subroutine of type_unification_real. Args are like the variables at the
- call site. ARG is an overloaded function (or template-id); we try
- deducing template args from each of the overloads, and if only one
- succeeds, we go with that. Modifies TARGS and returns 0 on success. */
+/* Subroutine of type_unification_real. Args are like the variables
+ at the call site. ARG is an overloaded function (or template-id);
+ we try deducing template args from each of the overloads, and if
+ only one succeeds, we go with that. Modifies TARGS and returns
+ true on success. */
-static int
+static bool
resolve_overloaded_unification (tree tparms,
tree targs,
tree parm,
@@ -11675,16 +11677,17 @@ resolve_overloaded_unification (tree tparms,
}
}
}
+ else if (TREE_CODE (arg) != OVERLOAD
+ && TREE_CODE (arg) != FUNCTION_DECL)
+ /* If ARG is, for example, "(0, &f)" then its type will be unknown
+ -- but the deduction does not succeed because the expression is
+ not just the function on its own. */
+ return false;
else
- {
- gcc_assert (TREE_CODE (arg) == OVERLOAD
- || TREE_CODE (arg) == FUNCTION_DECL);
-
- for (; arg; arg = OVL_NEXT (arg))
- good += try_one_overload (tparms, targs, tempargs, parm,
- TREE_TYPE (OVL_CURRENT (arg)),
- strict, sub_strict, addr_p);
- }
+ for (; arg; arg = OVL_NEXT (arg))
+ good += try_one_overload (tparms, targs, tempargs, parm,
+ TREE_TYPE (OVL_CURRENT (arg)),
+ strict, sub_strict, addr_p);
/* [temp.deduct.type] A template-argument can be deduced from a pointer
to function or pointer to member function argument if the set of
@@ -11702,9 +11705,9 @@ resolve_overloaded_unification (tree tparms,
TREE_VEC_ELT (targs, i) = TREE_VEC_ELT (tempargs, i);
}
if (good)
- return 0;
+ return true;
- return 1;
+ return false;
}
/* Subroutine of resolve_overloaded_unification; does deduction for a single
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 20b4f95b06e..1f99b0068fc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-07-07 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/32232
+ * g++.dg/template/overload9.C: New test.
+
2007-07-06 Daniel Berlin <dberlin@dberlin.org>
* gcc.dg/tree-ssa/ssa-pre-17.c: New test.
diff --git a/gcc/testsuite/g++.dg/template/overload9.C b/gcc/testsuite/g++.dg/template/overload9.C
new file mode 100644
index 00000000000..bc73c41fc88
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/overload9.C
@@ -0,0 +1,18 @@
+// PR c++/32232
+
+template <typename T> struct A;
+template <typename T> struct B {};
+template <typename T> A<T>& operator<<(A<T>&, const B<T>&);
+
+template <typename T>
+struct A
+{
+ A<T>& operator<<(A<T>& (*)(A<T>&)); // { dg-error "candidate" }
+};
+
+template <typename T> A<T>& foo(A<T>&);
+extern A<char> c;
+
+int main () {
+ c << (1, foo); // { dg-error "no match" }
+}