This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/36744] function modifying argument received by-value affects caller's variable when passed as rvalue



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-01-31 17:25 -------
Confirmed.

struct S
{
  S(): i(2) {}
  S(S const&);
  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;
}

declaring S(S const&); makes f() take a reference type and neither the
caller nor the callee performs a copy before writing to the passed by value y.

declaring S(S const&&); does not have this effect.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2009-01-31 17:25:01
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36744


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]