Commit 58326a56 by Dodji Seketeli Committed by Dodji Seketeli

re PR c++/42260 (ICE looking up template conversion operator)

Fix PR c++/42260

gcc/cp/ChangeLog:
	PR c++/42260
	* cp-tree.h (lookup_conversions): Add new bool parameter to
	declaration.
	* search.c (lookup_conversion): Use new bool parameter in
	definition.
	* call.c (add_builtin_candidates): Don't lookup template conversion
	(convert_class_to_reference, build_user_type_conversion_1,
	 build_op_call): Adjust.
	* cvt.c (build_expr_type_conversion): Likewise

gcc/testsuite/ChangeLog:
	PR c++/42260
	* conversion/cast2.C: New test.

From-SVN: r155415
parent 79e2daa9
2009-12-23 Dodji Seketeli <dodji@redhat.com>
PR c++/42260
* cp-tree.h (lookup_conversions): Add new bool parameter to
declaration.
* search.c (lookup_conversion): Use new bool parameter in
definition.
* call.c (add_builtin_candidates): Don't lookup template conversion
(convert_class_to_reference, build_user_type_conversion_1,
build_op_call): Adjust.
* cvt.c (build_expr_type_conversion): Likewise
2009-12-22 Jason Merrill <jason@redhat.com> 2009-12-22 Jason Merrill <jason@redhat.com>
PR c++/42466 PR c++/42466
......
...@@ -1009,7 +1009,7 @@ convert_class_to_reference (tree reference_type, tree s, tree expr, int flags) ...@@ -1009,7 +1009,7 @@ convert_class_to_reference (tree reference_type, tree s, tree expr, int flags)
struct z_candidate *cand; struct z_candidate *cand;
bool any_viable_p; bool any_viable_p;
conversions = lookup_conversions (s); conversions = lookup_conversions (s, /*lookup_template_convs_p=*/true);
if (!conversions) if (!conversions)
return NULL; return NULL;
...@@ -2362,7 +2362,8 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code, ...@@ -2362,7 +2362,8 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR) if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
return; return;
convs = lookup_conversions (argtypes[i]); convs = lookup_conversions (argtypes[i],
/*lookup_template_convs_p=*/false);
if (code == COND_EXPR) if (code == COND_EXPR)
{ {
...@@ -2851,7 +2852,8 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags) ...@@ -2851,7 +2852,8 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags)
reference to it)... */ reference to it)... */
} }
else else
conv_fns = lookup_conversions (fromtype); conv_fns = lookup_conversions (fromtype,
/*lookup_template_convs_p=*/true);
} }
candidates = 0; candidates = 0;
...@@ -3399,7 +3401,7 @@ build_op_call (tree obj, VEC(tree,gc) **args, tsubst_flags_t complain) ...@@ -3399,7 +3401,7 @@ build_op_call (tree obj, VEC(tree,gc) **args, tsubst_flags_t complain)
if (LAMBDA_TYPE_P (type)) if (LAMBDA_TYPE_P (type))
convs = NULL_TREE; convs = NULL_TREE;
else else
convs = lookup_conversions (type); convs = lookup_conversions (type, /*lookup_template_convs_p=*/true);
for (; convs; convs = TREE_CHAIN (convs)) for (; convs; convs = TREE_CHAIN (convs))
{ {
......
...@@ -4989,7 +4989,7 @@ extern int at_function_scope_p (void); ...@@ -4989,7 +4989,7 @@ extern int at_function_scope_p (void);
extern bool at_class_scope_p (void); extern bool at_class_scope_p (void);
extern bool at_namespace_scope_p (void); extern bool at_namespace_scope_p (void);
extern tree context_for_name_lookup (tree); extern tree context_for_name_lookup (tree);
extern tree lookup_conversions (tree); extern tree lookup_conversions (tree, bool);
extern tree binfo_from_vbase (tree); extern tree binfo_from_vbase (tree);
extern tree binfo_for_vbase (tree, tree); extern tree binfo_for_vbase (tree, tree);
extern tree look_for_overrides_here (tree, tree); extern tree look_for_overrides_here (tree, tree);
......
...@@ -1196,7 +1196,9 @@ build_expr_type_conversion (int desires, tree expr, bool complain) ...@@ -1196,7 +1196,9 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
if (!TYPE_HAS_CONVERSION (basetype)) if (!TYPE_HAS_CONVERSION (basetype))
return NULL_TREE; return NULL_TREE;
for (conv = lookup_conversions (basetype); conv; conv = TREE_CHAIN (conv)) for (conv = lookup_conversions (basetype, /*lookup_template_convs_p=*/true);
conv;
conv = TREE_CHAIN (conv))
{ {
int win = 0; int win = 0;
tree candidate; tree candidate;
......
...@@ -2419,10 +2419,13 @@ lookup_conversions_r (tree binfo, ...@@ -2419,10 +2419,13 @@ lookup_conversions_r (tree binfo,
functions in this node were selected. This function is effectively functions in this node were selected. This function is effectively
performing a set of member lookups as lookup_fnfield does, but performing a set of member lookups as lookup_fnfield does, but
using the type being converted to as the unique key, rather than the using the type being converted to as the unique key, rather than the
field name. */ field name.
If LOOKUP_TEMPLATE_CONVS_P is TRUE, the returned TREE_LIST contains
the non-hidden user-defined template conversion functions too. */
tree tree
lookup_conversions (tree type) lookup_conversions (tree type,
bool lookup_template_convs_p)
{ {
tree convs, tpl_convs; tree convs, tpl_convs;
tree list = NULL_TREE; tree list = NULL_TREE;
...@@ -2449,6 +2452,9 @@ lookup_conversions (tree type) ...@@ -2449,6 +2452,9 @@ lookup_conversions (tree type)
} }
} }
if (lookup_template_convs_p == false)
tpl_convs = NULL_TREE;
for (; tpl_convs; tpl_convs = TREE_CHAIN (tpl_convs)) for (; tpl_convs; tpl_convs = TREE_CHAIN (tpl_convs))
{ {
tree probe, next; tree probe, next;
......
2009-12-23 Dodji Seketeli <dodji@redhat.com>
PR c++/42260
* conversion/cast2.C: New test.
2009-12-22 Jason Merrill <jason@redhat.com> 2009-12-22 Jason Merrill <jason@redhat.com>
PR c++/42466 PR c++/42466
......
// Contributed by Dodji Seketeli <dodji@redhat.com>
// Origin: PR c++/42260
// { dg-do compile }
struct A
{
template<typename T> operator T*();
};
int i = *A();// { dg-error "no match" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment