aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2007-09-04 16:18:05 -0400
committerJason Merrill <jason@gcc.gnu.org>2007-09-04 16:18:05 -0400
commit9380ed8466ef43c4ec1e330fc3e7ddf36ceaa406 (patch)
treeb8e61e3eed80ab5a4bfb8bd4b19c07b43f0f5fb8 /gcc
parent4aeb38965b9a520a3db366879942639a4e64ad9a (diff)
downloadgcc-9380ed8466ef43c4ec1e330fc3e7ddf36ceaa406.zip
gcc-9380ed8466ef43c4ec1e330fc3e7ddf36ceaa406.tar.gz
gcc-9380ed8466ef43c4ec1e330fc3e7ddf36ceaa406.tar.bz2
re PR c++/31419 (template user defined conversion operator instantiated for conversion to self)
PR c++/31419 * call.c (reference_binding): Don't look for user-defined conversions to the same type. From-SVN: r128102
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/call.c7
-rw-r--r--gcc/testsuite/g++.dg/conversion/self1.C15
3 files changed, 25 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e517f89..ab7cb5f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 8fb818b..dd41b9d 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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
index 0000000..f36500a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/self1.C
@@ -0,0 +1,15 @@
+// PR c++/31419
+
+struct B
+{
+ template<typename T>
+ operator T const& () const
+ {
+ return 42;
+ }
+};
+
+B f()
+{
+ return B();
+}