From: Jason Merrill Date: Wed, 11 Feb 2009 05:23:02 +0000 (-0500) Subject: re PR c++/36744 ([C++0x] function modifying argument received by-value affects caller... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=952e24fed662bec5e6076a1adb6b5642a926c86e;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5b354374f48..3c1975ff708 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-02-10 Jason Merrill + + PR c++/36744 + * tree.c (lvalue_p_1): Condition rvalue ref handling on + treat_class_rvalues_as_lvalues, too. + 2009-02-10 Paolo Carlini PR c++/34397 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 606a9464974..456abfc9443 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 d9a63e073be..4cb62582130 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-02-11 Jason Merrill + + PR c++/36744 + * g++.dg/cpp0x/rv9p.C: New test. + 2009-02-10 Eric Botcazou * 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 00000000000..ec08a824865 --- /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(y)); + if (y.i != 2) + abort (); + return 0; +}