[Bug c++/49528] New: g++ fails to destroy temporary object when subobject is used to initialize a reference

jason at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Jun 25 03:33:00 GMT 2011


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

           Summary: g++ fails to destroy temporary object when subobject
                    is used to initialize a reference
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jason@gcc.gnu.org


I believe that r should point to a temporary int and the A temporary destroyed
at the end of the declaration statement rather than have its lifetime extended
to the end of the block.  In any case, never destroying it is clearly broken.

int d;
struct A
{
  int i;
  ~A() { ++d; };
};

int main()
{
  { const int &r = A().i; }
  if (d != 1)
    return 1;
}



More information about the Gcc-bugs mailing list