This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/17435] New: Temporay bound to reference is immediately destructed
- From: "vlukas at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Sep 2004 11:05:28 -0000
- Subject: [Bug c++/17435] New: Temporay bound to reference is immediately destructed
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
If a reference to const is bound to an temporary object of derived type, it
seems as if the lifetime of the temporary is not extended to the lifetime of
the reference.
The small program at the bottom, compiled with gcc version 4.0.0 20040912
(experimental) gives this Output:
~A()
A::func()
With gcc 3.3.4 the same program generates this Output:
A::func()
~A()
I think this is the correct behaviour.
To reproduce, save the following snippet to a file "name.cpp" and compile with
gcc version 4.0.0 20040912:
c++ -Wall -o name name.cpp
Then execute "name".
------------------------------------------------------
int printf(char const*, ...);
struct A
{
void func() const
{
printf(" A::func()\n");
}
~A()
{
printf("~A()\n");
}
};
struct B : public A
{
};
int main()
{
A const& r1 = B();
r1.func();
}
----------------------------------------------------------
--
Summary: Temporay bound to reference is immediately destructed
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: vlukas at gmx dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17435