According to 12.2 ; 5, in the following code:

int count;

class C
{
public:
  int i;
  C() : i(1) { ++count;}
  C(const C &c) : i(c.i) { ++count;}
  ~C() { --count;}
};

int
f ()
{
  static const C &c = C();
  return c.i;
}

int
main ()
{
  int i = f ();
  return count < i;
}

the temporary to which the reference c is bound in f should persist till
the program exits.  However, although it is only initialized once (as it
ought to), it is destroyed each time the function f returns.


-- 
           Summary: temporary to which static storage duration reference is
                    bound destroyed too early
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: amylaar at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29360

Reply via email to