re PR c++/36744 ([C++0x] function modifying argument received by-value affects caller...
authorJason Merrill <jason@redhat.com>
Wed, 11 Feb 2009 05:23:02 +0000 (00:23 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 11 Feb 2009 05:23:02 +0000 (00:23 -0500)
        PR c++/36744
        * tree.c (lvalue_p_1): Condition rvalue ref handling on
        treat_class_rvalues_as_lvalues, too.

From-SVN: r144091

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/rv9p.C [new file with mode: 0644]

index 5b354374f4830eb8e46f487f3f18f90d3945c26e..3c1975ff708f24fcbde5b4288645763fcad052bd 100644 (file)
@@ -1,3 +1,9 @@
+2009-02-10  Jason Merrill  <jason@redhat.com>
+
+       PR c++/36744
+       * tree.c (lvalue_p_1): Condition rvalue ref handling on
+       treat_class_rvalues_as_lvalues, too.
+
 2009-02-10  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/34397
index 606a94649745d03c0e3efc59176064dd200327d6..456abfc9443db781c1ec21128996761361cf2f47 100644 (file)
@@ -82,7 +82,12 @@ lvalue_p_1 (tree ref,
          && TREE_CODE (ref) != PARM_DECL
          && TREE_CODE (ref) != VAR_DECL
          && TREE_CODE (ref) != COMPONENT_REF)
-       return clk_none;
+       {
+         if (CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (ref))))
+           return treat_class_rvalues_as_lvalues ? clk_class : clk_none;
+         else
+           return clk_none;
+       }
 
       /* lvalue references and named rvalue references are lvalues.  */
       return clk_ordinary;
index d9a63e073be36c16873c86bfc4e88984cde3919e..4cb62582130f65bc4d26d2afd15d66d2cd8d434e 100644 (file)
@@ -1,3 +1,8 @@
+2009-02-11  Jason Merrill  <jason@redhat.com>
+
+       PR c++/36744
+       * g++.dg/cpp0x/rv9p.C: New test.
+
 2009-02-10  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/aliasing3.adb: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv9p.C b/gcc/testsuite/g++.dg/cpp0x/rv9p.C
new file mode 100644 (file)
index 0000000..ec08a82
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/36744
+// { dg-options "-std=c++0x" }
+// { dg-do run }
+
+struct S
+{
+  S(): i(2) {}
+  S(S const&s): i(s.i) {}
+  int i;
+};
+
+void f(S x) { x.i = 0; }
+
+extern "C" void abort (void);
+int main()
+{
+  S y;
+  f(static_cast<S&&>(y));
+  if (y.i != 2)
+    abort ();
+  return 0;
+}