* C++ PATCHes for DR 1328, c++/49267, c++/49458
@ 2011-09-05 4:29 Jason Merrill
2011-09-18 8:41 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2011-09-05 4:29 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 532 bytes --]
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.
[-- Attachment #2: dr-1328.patch --]
[-- Type: text/x-patch, Size: 2285 bytes --]
commit e41e0ca96a427873cf7d6d8228358362ca7637ca
Author: Jason Merrill <jason@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;
[-- Attachment #3: ref-bind-2.patch --]
[-- Type: text/x-patch, Size: 779 bytes --]
commit 41e2f64d32ca6f850f2907387285ad0d37e93a25
Author: Jason Merrill <jason@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))
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCHes for DR 1328, c++/49267, c++/49458
2011-09-05 4:29 C++ PATCHes for DR 1328, c++/49267, c++/49458 Jason Merrill
@ 2011-09-18 8:41 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2011-09-18 8:41 UTC (permalink / raw)
Cc: gcc-patches List
On 09/05/2011 12:29 AM, Jason Merrill wrote:
> Also applying the compare_ics hunk to 4.6.
This caused c++/50442, so I'm reverting it.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-09-17 22:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-05 4:29 C++ PATCHes for DR 1328, c++/49267, c++/49458 Jason Merrill
2011-09-18 8:41 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).