This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/20416] Incorrect lifetime for temporary with static const reference
- From: "rsandifo at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Nov 2005 16:09:00 -0000
- Subject: [Bug c++/20416] Incorrect lifetime for temporary with static const reference
- References: <bug-20416-10246@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #1 from rsandifo at gcc dot gnu dot org 2005-11-21 16:09 -------
Confirmed. Here's a dejagnu-style testcase:
// PR c++/20416. We correctly constructed the temporary S in foo(),
// but incorrectly destroyed it every time foo() was called.
// { dg-do run }
extern "C" void abort (void);
namespace { int counter; }
struct S {
S() { counter++; }
S(const S &) { counter++; }
~S() { counter--; }
};
void
foo (void)
{
static const S &s = S();
if (counter != 1)
abort ();
}
int main ()
{
if (counter != 0)
abort ();
foo ();
foo ();
}
--
rsandifo at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rsandifo at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Known to fail| |3.4.5 4.1.0
Last reconfirmed|0000-00-00 00:00:00 |2005-11-21 16:09:00
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20416