public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/48370] New: G++ fails to extend reference temporary lifetime in some situations
Date: Wed, 30 Mar 2011 17:35:00 -0000	[thread overview]
Message-ID: <bug-48370-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2011-03-30 17:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-30 17:35 jason at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-48370-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).