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
This commit is contained in:
Jason Merrill 2009-02-11 00:23:02 -05:00 committed by Jason Merrill
parent 1d428010b4
commit 952e24fed6
4 changed files with 39 additions and 1 deletions

View 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

View 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;

View 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.

View file

@ -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;
}