OSDN Git Service

Fix PR c++/42260
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 Dec 2009 00:31:33 +0000 (00:31 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 Dec 2009 00:31:33 +0000 (00:31 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155415 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/cvt.c
gcc/cp/search.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/cast2.C [new file with mode: 0644]

index 65d40e2..ecd0c7a 100644 (file)
@@ -1,3 +1,15 @@
+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>
 
        PR c++/42466
index 67f4465..3fcbccf 100644 (file)
@@ -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))
     {
index 469dcec..531ede1 100644 (file)
@@ -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);
index 6f3b56e..b4cc2b3 100644 (file)
@@ -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;
index 3e9bec0..c07a5e6 100644 (file)
@@ -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;
index 59d3a09..6740287 100644 (file)
@@ -1,3 +1,8 @@
+2009-12-23  Dodji Seketeli  <dodji@redhat.com>
+
+       PR c++/42260
+       * conversion/cast2.C: New test.
+
 2009-12-22  Jason Merrill  <jason@redhat.com>
 
        PR c++/42466
diff --git a/gcc/testsuite/g++.dg/conversion/cast2.C b/gcc/testsuite/g++.dg/conversion/cast2.C
new file mode 100644 (file)
index 0000000..3868d74
--- /dev/null
@@ -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" }
+