[Bug c++/20416] Incorrect lifetime for temporary with static const reference

rsandifo at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Nov 21 16:09:00 GMT 2005



------- 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



More information about the Gcc-bugs mailing list