This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/18272] weird behaviour on temporary return values
- From: "philippe dot haution at mines-paris dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Nov 2004 14:54:15 -0000
- Subject: [Bug c++/18272] weird behaviour on temporary return values
- References: <20041102123746.18272.philippe.haution@mines-paris.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From philippe dot haution at mines-paris dot org 2004-11-02 14:54 -------
You wrote about reference incrementing, but as far as auto_ptrs are concerned,
there's only ownership transfer of the underlying pointer.
res1 and res2 are OK, no problem about that.
But res5 = *(ert().release()); should and did not cause any exception because
this code is absolutely correct. Each call to the ert() function allocates a new
vector wrapped in a new temporary auto_ptr, so you can perform as many
ert().release() as you like and I am afraid I don't agree at all with your
comment about this line.
My initial concern was about :
vector<int> *res3 = ert().get();
vector<int>& res4 = *(ert());
After those two lines, it looks like res3 and res4 have lost the expected
result. If "temporary return values only last until the statement is finished",
then it's incorrect code and gcc's behaviour is OK. Then why do those 2
variables res3 and res4 hold the right result if I just add the instruction
about res5 ?
Try to execute the program with and without this instruction and see.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18272