From: Jason Merrill Date: Tue, 20 Aug 2013 12:59:24 +0000 (-0400) Subject: re PR c++/58119 (Invalid ambiguous default type conversion with only a single invalid... X-Git-Tag: releases/gcc-4.7.4~525 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e7d7fee28ec97343fcacfb254af14a420e2e3c2;p=thirdparty%2Fgcc.git re PR c++/58119 (Invalid ambiguous default type conversion with only a single invalid conversion listed.) PR c++/58119 * cp-tree.h (WILDCARD_TYPE_P): Split out from... (MAYBE_CLASS_TYPE_P): ...here. * cvt.c (build_expr_type_conversion): Don't complain about a template that can't match the desired type category. From-SVN: r201881 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5b5acd930699..247344281842 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2013-08-20 Jason Merrill + + PR c++/58119 + * cp-tree.h (WILDCARD_TYPE_P): Split out from... + (MAYBE_CLASS_TYPE_P): ...here. + * cvt.c (build_expr_type_conversion): Don't complain about a + template that can't match the desired type category. + 2012-12-03 Paolo Carlini PR c++/54170 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 0c1601b474a4..b4fdda7999ad 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1191,17 +1191,20 @@ enum languages { lang_c, lang_cplusplus, lang_java }; /* The _DECL for this _TYPE. */ #define TYPE_MAIN_DECL(NODE) (TYPE_STUB_DECL (TYPE_MAIN_VARIANT (NODE))) -/* Nonzero if T is a class (or struct or union) type. Also nonzero - for template type parameters, typename types, and instantiated - template template parameters. Keep these checks in ascending code - order. */ -#define MAYBE_CLASS_TYPE_P(T) \ +/* Nonzero if T is a type that could resolve to any kind of concrete type + at instantiation time. */ +#define WILDCARD_TYPE_P(T) \ (TREE_CODE (T) == TEMPLATE_TYPE_PARM \ || TREE_CODE (T) == TYPENAME_TYPE \ || TREE_CODE (T) == TYPEOF_TYPE \ || TREE_CODE (T) == BOUND_TEMPLATE_TEMPLATE_PARM \ - || TREE_CODE (T) == DECLTYPE_TYPE \ - || CLASS_TYPE_P (T)) + || TREE_CODE (T) == DECLTYPE_TYPE) + +/* Nonzero if T is a class (or struct or union) type. Also nonzero + for template type parameters, typename types, and instantiated + template template parameters. Keep these checks in ascending code + order. */ +#define MAYBE_CLASS_TYPE_P(T) (WILDCARD_TYPE_P (T) || CLASS_TYPE_P (T)) /* Set CLASS_TYPE_P for T to VAL. T must be a class, struct, or union type. */ diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index d7ad05b1583c..fddba51cef77 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1539,17 +1539,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)) @@ -1583,11 +1572,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) { if (complain) diff --git a/gcc/testsuite/g++.dg/template/delete2.C b/gcc/testsuite/g++.dg/template/delete2.C new file mode 100644 index 000000000000..b6ab380c9f9d --- /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" } +}