This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33885] New: member reference to a temporary object being deleted too eary
- From: "gzljg at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Oct 2007 20:05:16 -0000
- Subject: [Bug c++/33885] New: member reference to a temporary object being deleted too eary
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
class A{
// ....
};
class B{
public:
explicit B(const A& a)
: i_a(a)
{
}
~B()
{
}
private:
const A& i_a;
};
A returnA( const char* arg )
{
return A(/*arg*/);
}
foo()
{
const A& aRef = returnA("FirstObject"); // ..... (1)
{
const B b(returnA("SecondObject")); // ..... (2)
///...
typedef int outofscope_block; // ..... (3)
}
typedef char outofscope_function; // ..... (4)
}
temporary object created and referenced by aRef is being deleted when aRef goes
out of scope in foo, as Expected.
temporary object created and referenced by B::i_a is being deleted right after
object b's construction, Not expected. It should(?) have the same life time as
the B::i_a(thus b), such as deleted _after_ line (3) --- If this assumpsion is
false, then what's the difference between a 'plain reference' and 'member
reference' herein??
BTW, it works as expected on SunCC compiler. It core dumps on gcc 3.3.3 while
having (empty/invalid) data for i_a on gcc 4.1.2 but not coring.
--
Summary: member reference to a temporary object being deleted too
eary
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gzljg at hotmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33885