[PATCH] PR c++/42260

Dodji Seketeli dodji@redhat.com
Wed Dec 23 03:11:00 GMT 2009


On Tue, Dec 22, 2009 at 04:01:12PM -0500, Jason Merrill wrote:
> I'd rather not add external calls to _1 functions (though I've done
> it myself in the past).  Either add the new parameter and change all
> the callers, or add a new function named
> lookup_non_template_conversions to call from here.

No problem. I have added a new parameter to lookup_conversions, and
this is the patch I'd plan to commit.

I have rebased my tree against svn trunk and I am re-running a bootstrap
at the moment, just to make sure.

> OK with that change.

Thanks.

        Dodji

commit e1ff1fc67cd420a08c13af119182787a9ea8f2c8
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Tue Dec 22 20:59:50 2009 +0100

    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.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 67f4465..3fcbccf 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1009,7 +1009,7 @@ convert_class_to_reference (tree reference_type, tree s, tree expr, int flags)
   struct z_candidate *cand;
   bool any_viable_p;
 
-  conversions = lookup_conversions (s);
+  conversions = lookup_conversions (s, /*lookup_template_convs_p=*/true);
   if (!conversions)
     return NULL;
 
@@ -2362,7 +2362,8 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
 	  if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
 	    return;
 
-	  convs = lookup_conversions (argtypes[i]);
+	  convs = lookup_conversions (argtypes[i],
+				      /*lookup_template_convs_p=*/false);
 
 	  if (code == COND_EXPR)
 	    {
@@ -2851,7 +2852,8 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags)
 	     reference to it)...  */
 	}
       else
-	conv_fns = lookup_conversions (fromtype);
+	conv_fns = lookup_conversions (fromtype,
+				       /*lookup_template_convs_p=*/true);
     }
 
   candidates = 0;
@@ -3399,7 +3401,7 @@ build_op_call (tree obj, VEC(tree,gc) **args, tsubst_flags_t complain)
   if (LAMBDA_TYPE_P (type))
     convs = NULL_TREE;
   else
-    convs = lookup_conversions (type);
+    convs = lookup_conversions (type, /*lookup_template_convs_p=*/true);
 
   for (; convs; convs = TREE_CHAIN (convs))
     {
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 469dcec..531ede1 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4989,7 +4989,7 @@ extern int at_function_scope_p			(void);
 extern bool at_class_scope_p			(void);
 extern bool at_namespace_scope_p		(void);
 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_for_vbase			(tree, tree);
 extern tree look_for_overrides_here		(tree, tree);
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 6f3b56e..b4cc2b3 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -1196,7 +1196,9 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
   if (!TYPE_HAS_CONVERSION (basetype))
     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;
       tree candidate;
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 3e9bec0..c07a5e6 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -2419,10 +2419,13 @@ lookup_conversions_r (tree binfo,
    functions in this node were selected.  This function is effectively
    performing a set of member lookups as lookup_fnfield does, but
    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
-lookup_conversions (tree type)
+lookup_conversions (tree type,
+		    bool lookup_template_convs_p)
 {
   tree convs, tpl_convs;
   tree list = NULL_TREE;
@@ -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))
     {
       tree probe, next;
diff --git a/gcc/testsuite/g++.dg/conversion/cast2.C b/gcc/testsuite/g++.dg/conversion/cast2.C
new file mode 100644
index 0000000..3868d74
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/cast2.C
@@ -0,0 +1,11 @@
+// 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" }
+



More information about the Gcc-patches mailing list