This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]