These two PRs have to do with comparing conversion operators that return
lvalue or rvalue references. The fix for 49458 is to consider that
directly when deciding whether the rvalueness matches the target
reference, before an rvalue reference to function has decayed to an
lvalue. Part of this fixes 49267, but I've also fixed (in the second
patch) the code that incorrectly decided that an rvalue reference to int
was an lvalue.
Tested x86_64-pc-linux-gnu, applying to trunk. Also applying the
compare_ics hunk to 4.6.
commit e41e0ca96a427873cf7d6d8228358362ca7637ca
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Aug 31 11:22:32 2011 -0400
DR 1328
* call.c (reference_binding): Set rvaluedness_matches_p properly
for reference to function conversion ops.
(compare_ics): Adjust.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 8421260..1fa5fc8 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1652,6 +1652,10 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
/* The top-level caller requested that we pretend that the lvalue
be treated as an rvalue. */
conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
+ else if (TREE_CODE (rfrom) == REFERENCE_TYPE)
+ /* Handle rvalue reference to function properly. */
+ conv->rvaluedness_matches_p
+ = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
else
conv->rvaluedness_matches_p
= (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
@@ -7960,13 +7964,13 @@ compare_ics (conversion *ics1, conversion *ics2)
if (ref_conv1 && ref_conv2)
{
- if (!ref_conv1->this_p && !ref_conv2->this_p
- && (TYPE_REF_IS_RVALUE (ref_conv1->type)
- != TYPE_REF_IS_RVALUE (ref_conv2->type)))
+ if (!ref_conv1->this_p && !ref_conv2->this_p)
{
- if (ref_conv1->rvaluedness_matches_p)
+ if (ref_conv1->rvaluedness_matches_p
+ > ref_conv2->rvaluedness_matches_p)
return 1;
- if (ref_conv2->rvaluedness_matches_p)
+ if (ref_conv2->rvaluedness_matches_p
+ > ref_conv1->rvaluedness_matches_p)
return -1;
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-conv1.C b/gcc/testsuite/g++.dg/cpp0x/rv-conv1.C
new file mode 100644
index 0000000..3852991
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-conv1.C
@@ -0,0 +1,9 @@
+// PR c++/49267
+// { dg-options -std=c++0x }
+
+struct X {
+ operator int&();
+ operator int&&();
+};
+
+int&&x = X();
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-func3.C b/gcc/testsuite/g++.dg/cpp0x/rv-func3.C
new file mode 100644
index 0000000..8504682
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-func3.C
@@ -0,0 +1,10 @@
+// DR 1328
+// { dg-options -std=c++0x }
+
+template <class T> struct A {
+ operator T&(); // #1
+ operator T&&(); // #2
+};
+typedef int Fn();
+A<Fn> a;
+Fn&& f = a;
commit 41e2f64d32ca6f850f2907387285ad0d37e93a25
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Aug 31 16:49:33 2011 -0400
* call.c (reference_binding): Don't set is_lvalue for an rvalue
reference rfrom.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1fa5fc8..c707d66 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1576,9 +1576,10 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
if (TREE_CODE (from) == REFERENCE_TYPE)
{
- /* Anything with reference type is an lvalue. */
- is_lvalue = clk_ordinary;
from = TREE_TYPE (from);
+ if (!TYPE_REF_IS_RVALUE (rfrom)
+ || TREE_CODE (from) == FUNCTION_TYPE)
+ is_lvalue = clk_ordinary;
}
if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))