public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48370] New: G++ fails to extend reference temporary lifetime in some situations
@ 2011-03-30 17:35 jason at gcc dot gnu.org
  2011-08-08 13:56 ` [Bug c++/48370] " jason at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2011-03-30 17:35 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: G++ fails to extend reference temporary lifetime in
                    some situations
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jason@gcc.gnu.org


In addition to the issue described in bug 26714, we fail to extend the
temporary lifetime if the reference we're binding to is a subobject:

extern "C" void abort();
bool ok;

struct A {
  A(int) { }
  ~A() { if (!ok) abort(); }
};

struct C
{
  const A& ar;
};

int main()
{
  C c = { 1 };
  ok = true;
}

This problem is more severe in C++0x, where you can have initializer_list
subobjects:

// Test that we properly extend the lifetime of the initializer_list
// array even if the initializer_list is a subobject.
// { dg-options -std=c++0x }
// { dg-do run }

#include <initializer_list>

extern "C" void abort();
bool ok;

struct A {
  A(int) { }
  ~A() { if (!ok) abort(); }
};

typedef std::initializer_list<A> AL;
typedef std::initializer_list<AL> AL2;
typedef std::initializer_list<AL2> AL3;

struct B {
  AL al;
  const AL& alr;
};

int main()
{
  AL ar[] = {{1,2},{3,4}};
  B b = {{5,6},{7,8}};
  AL3 al3 = {{{1},{2},{3}}};
  ok = true;
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-11-05  3:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-30 17:35 [Bug c++/48370] New: G++ fails to extend reference temporary lifetime in some situations jason at gcc dot gnu.org
2011-08-08 13:56 ` [Bug c++/48370] " jason at gcc dot gnu.org
2011-11-04 12:54 ` jason at gcc dot gnu.org
2011-11-04 14:46 ` jason at gcc dot gnu.org
2011-11-05  3:28 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).