[Bug c++/63364] GCC optimizer causing memory corruption
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Sep 25 03:38:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63364
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> B(A const*const&aa):a(aa){}
> B*b=new B(this);
There is a temporary variable being created there and it goes out of scope
after the statement is finished. The reason is because this is not a lvalue,
prvalue.
Here is the quote from the standard:
In the body of a non-static (9.3) member function, the keyword this is a
prvalue expression whose value
is the address of the object for which the function is called.
More information about the Gcc-bugs
mailing list