This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: GCC compile problem ...
- From: Sebastian Huber <sebastian-huber at web dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 28 Sep 2002 00:52:38 -0700
- Subject: Re: GCC compile problem ...
- References: <B9B9F22C.4AB1%eljay@adobe.com>
Hello John,
On Friday 27 September 2002 09:31, John Love-Jensen wrote:
> Hi Gerhard,
>
> The TEMPORARY from test.getString is being set to a REFERENCE.
>
> The TEMPORARY is destructed, more-or-less, after the semicolon that set the
> string reference to the temporary.
>
> The cout << s << "\n"; is operating on the s string that has been
> destructed, which is very dangerous.
I think, that this is not true. If you assign a temporary object to a constant
reference, the object will survive until the reference is destroyed.
> Who knows what state that freed STACK
> memory and HEAP memory will be in, especially during the machinations of
> the ostream processing.
>
> Borland C++ 5.5 and Microsoft Visual C++ 6.0 should be ashamed. Shame.
> Shame.
>
> --Eljay
Bye