re PR c++/49389 ([C++0x] Wrong value category for pointer-to-member expression with...
authorJason Merrill <jason@redhat.com>
Tue, 14 Jun 2011 18:15:58 +0000 (14:15 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 14 Jun 2011 18:15:58 +0000 (14:15 -0400)
PR c++/49389
* typeck2.c (build_m_component_ref): Preserve rvalueness.

From-SVN: r175043

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/rv-dotstar.C [new file with mode: 0644]

index a6c866567b82b0dff4dde32efd3adb07df8cf79a..5970440731fc468be978dc8b240df83d4abd7a5c 100644 (file)
@@ -1,5 +1,8 @@
 2011-06-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/49389
+       * typeck2.c (build_m_component_ref): Preserve rvalueness.
+
        PR c++/49369
        * class.c (build_base_path): Fix cv-quals in unevaluated context.
 
index fa64d1d72539fcfedf824ccae9a3ea2d529ab736..d72f57ec937acbcc00ba9bec5545cad12e148b6b 100644 (file)
@@ -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);
index 7d5e46ae7c8b2342fc02706aabe7aac0f966e21e..1ca37e3490d7f741ce05b2cb148907e276e56db0 100644 (file)
@@ -1,5 +1,8 @@
 2011-06-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/49389
+       * g++.dg/cpp0x/rv-dotstar.C: New.
+
        PR c++/49369
        * g++.dg/cpp0x/decltype30.C: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-dotstar.C b/gcc/testsuite/g++.dg/cpp0x/rv-dotstar.C
new file mode 100644 (file)
index 0000000..65aac8d
--- /dev/null
@@ -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;