From c5918c2199ee193f86cfafb9ad9fb040d7a60a14 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 20 Aug 2013 08:58:47 -0400 Subject: [PATCH] re PR c++/58119 (Invalid ambiguous default type conversion with only a single invalid conversion listed.) PR c++/58119 * cvt.c (build_expr_type_conversion): Don't complain about a template that can't match the desired type category. From-SVN: r201880 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cvt.c | 23 +++++++++++----------- gcc/testsuite/g++.dg/template/delete2.C | 26 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/delete2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5f55ca2e3ae..c18bcb52263 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-08-20 Jason Merrill + + PR c++/58119 + * cvt.c (build_expr_type_conversion): Don't complain about a + template that can't match the desired type category. + 2013-08-20 Gabriel Dos Reis * error.c (pp_ggc_formatted_text): New. diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 532e8fd9d6b..08c026da178 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1590,17 +1590,6 @@ build_expr_type_conversion (int desires, tree expr, bool complain) if (DECL_NONCONVERTING_P (cand)) continue; - if (TREE_CODE (cand) == TEMPLATE_DECL) - { - if (complain) - { - error ("ambiguous default type conversion from %qT", - basetype); - error (" candidate conversions include %qD", cand); - } - return error_mark_node; - } - candidate = non_reference (TREE_TYPE (TREE_TYPE (cand))); switch (TREE_CODE (candidate)) @@ -1634,11 +1623,23 @@ build_expr_type_conversion (int desires, tree expr, bool complain) break; default: + /* A wildcard could be instantiated to match any desired + type, but we can't deduce the template argument. */ + if (WILDCARD_TYPE_P (candidate)) + win = true; break; } if (win) { + if (TREE_CODE (cand) == TEMPLATE_DECL) + { + if (complain) + error ("default type conversion can't deduce template" + " argument for %qD", cand); + return error_mark_node; + } + if (winner) { tree winner_type diff --git a/gcc/testsuite/g++.dg/template/delete2.C b/gcc/testsuite/g++.dg/template/delete2.C new file mode 100644 index 00000000000..b6ab380c9f9 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/delete2.C @@ -0,0 +1,26 @@ +// PR c++/58119 + +template +struct A +{ + operator T*(); + template + operator A(); +}; + +template +struct B +{ + operator T*(); + template + operator A*(); +}; + +int main() +{ + A a; + delete a; + + B b; + delete b; // { dg-error "template|delete" } +} -- 2.30.2