aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2009-02-11 00:23:02 -0500
committerJason Merrill <jason@gcc.gnu.org>2009-02-11 00:23:02 -0500
commit952e24fed662bec5e6076a1adb6b5642a926c86e (patch)
treecd5dab2eab6b58e365a98497f181d91f83dc2e88
parent1d428010b4e72e25582ae6ba45901a6072f1bb94 (diff)
downloadgcc-952e24fed662bec5e6076a1adb6b5642a926c86e.zip
gcc-952e24fed662bec5e6076a1adb6b5642a926c86e.tar.gz
gcc-952e24fed662bec5e6076a1adb6b5642a926c86e.tar.bz2
re PR c++/36744 ([C++0x] function modifying argument received by-value affects caller's variable when passed as rvalue)
PR c++/36744 * tree.c (lvalue_p_1): Condition rvalue ref handling on treat_class_rvalues_as_lvalues, too. From-SVN: r144091
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/tree.c7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/rv9p.C22
4 files changed, 39 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5b35437..3c1975f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 606a946..456abfc 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d9a63e0..4cb6258 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..ec08a82
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv9p.C
@@ -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;
+}