re PR c++/31419 (template user defined conversion operator instantiated for conversio...
authorJason Merrill <jason@redhat.com>
Tue, 4 Sep 2007 20:18:05 +0000 (16:18 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 4 Sep 2007 20:18:05 +0000 (16:18 -0400)
        PR c++/31419
        * call.c (reference_binding): Don't look for user-defined conversions
        to the same type.

From-SVN: r128102

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/conversion/self1.C [new file with mode: 0644]

index e517f89d11278189d7acde5c4d9eea7406e7fa3e..ab7cb5ffea4069fda1eb7f80a874605b265503ae 100644 (file)
@@ -1,5 +1,9 @@
 2007-09-04  Jason Merrill  <jason@redhat.com>
 
+       PR c++/31419
+       * call.c (reference_binding): Don't look for user-defined conversions
+       to the same type.
+
        PR c++/31411
        * except.c (initialize_handler_parm): Put a CLEANUP_POINT_EXPR inside
        the MUST_NOT_THROW_EXPR.
index 8fb818b64a64e590f49589a4c374b7626d7436f6..dd41b9d8168fb91bacbc5b3dba5f165cea8f3655 100644 (file)
@@ -1200,7 +1200,12 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
 
       return conv;
     }
-  else if (CLASS_TYPE_P (from) && !(flags & LOOKUP_NO_CONVERSION))
+  /* [class.conv.fct] A conversion function is never used to convert a
+     (possibly cv-qualified) object to the (possibly cv-qualified) same
+     object type (or a reference to it), to a (possibly cv-qualified) base
+     class of that type (or a reference to it).... */
+  else if (CLASS_TYPE_P (from) && !related_p
+          && !(flags & LOOKUP_NO_CONVERSION))
     {
       /* [dcl.init.ref]
 
diff --git a/gcc/testsuite/g++.dg/conversion/self1.C b/gcc/testsuite/g++.dg/conversion/self1.C
new file mode 100644 (file)
index 0000000..f36500a
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/31419
+
+struct B
+{
+  template<typename T>
+  operator T const& () const
+  {
+    return 42;
+  }
+};
+
+B f()
+{
+  return B();
+}