public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/49389 (wrong value category for .*)
@ 2011-06-14 18:45 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-06-14 18:45 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 117 bytes --]

If the object expression is an rvalue, the result should be as well.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 49389.patch --]
[-- Type: text/x-patch, Size: 1626 bytes --]

commit 93619457bb3756b091d86a13d1aa72880bb1ac62
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 13 22:19:24 2011 -0400

    	PR c++/49389
    	* typeck2.c (build_m_component_ref): Preserve rvalueness.

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index fa64d1d..d72f57e 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1551,6 +1551,7 @@ build_m_component_ref (tree datum, tree component)
 
   if (TYPE_PTRMEM_P (ptrmem_type))
     {
+      bool is_lval = real_lvalue_p (datum);
       tree ptype;
 
       /* Compute the type of the field, as described in [expr.ref].
@@ -1573,7 +1574,11 @@ build_m_component_ref (tree datum, tree component)
       datum = build2 (POINTER_PLUS_EXPR, ptype,
 		      fold_convert (ptype, datum),
 		      build_nop (sizetype, component));
-      return cp_build_indirect_ref (datum, RO_NULL, tf_warning_or_error);
+      datum = cp_build_indirect_ref (datum, RO_NULL, tf_warning_or_error);
+      /* If the object expression was an rvalue, return an rvalue.  */
+      if (!is_lval)
+	datum = move (datum);
+      return datum;
     }
   else
     return build2 (OFFSET_REF, type, datum, component);
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-dotstar.C b/gcc/testsuite/g++.dg/cpp0x/rv-dotstar.C
new file mode 100644
index 0000000..65aac8d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-dotstar.C
@@ -0,0 +1,13 @@
+// PR c++/49389
+// { dg-options -std=c++0x }
+
+template<class T> T&& val();
+
+struct A {};
+
+typedef decltype(val<A>().*val<int A::*>()) type;
+
+template<class> struct assert_type;
+template<> struct assert_type<int&&> {};
+
+assert_type<type> test;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-06-14 18:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-14 18:45 C++ PATCH for c++/49389 (wrong value category for .*) 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).