public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57745] New: missing recursive lifetime extension within std::initializer_list
@ 2013-06-27 23:08 richard-gccbugzilla at metafoo dot co.uk
  2013-06-27 23:22 ` [Bug c++/57745] " paolo.carlini at oracle dot com
  0 siblings, 1 reply; 2+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2013-06-27 23:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57745
           Summary: missing recursive lifetime extension within
                    std::initializer_list
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: richard-gccbugzilla at metafoo dot co.uk

Consider:

#include <iostream>
struct A {
   A() { std::cout << " A()" << std::endl; }
  ~A() { std::cout << "~A()" << std::endl; }
};
struct B {
  const A &a;
  ~B() { std::cout << "~B()" << std::endl; }
};
struct C {
  std::initializer_list<B> b;
  ~C() { std::cout << "~C()" << std::endl; }
};
int main() {
  const C &c = C{ { { A() }, { A() } } };
  std::cout << "-----" << std::endl;
}

This should print:

 A()
 A()
-----
~C()
~B()
~A()
~B()
~A()

... but g++ destroys the two A temporaries at the end of the full-expression.
They are lifetime-extended because they are bound to B::a references in the
aggregate-initialization of the B subobjects of the underlying array of the
initializer_list, which is itself lifetime-extended.


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

* [Bug c++/57745] missing recursive lifetime extension within std::initializer_list
  2013-06-27 23:08 [Bug c++/57745] New: missing recursive lifetime extension within std::initializer_list richard-gccbugzilla at metafoo dot co.uk
@ 2013-06-27 23:22 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 2+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-27 23:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
First blush seems related to PR54293, but I didn't study the latter seriously
enough.


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

end of thread, other threads:[~2013-06-27 23:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-27 23:08 [Bug c++/57745] New: missing recursive lifetime extension within std::initializer_list richard-gccbugzilla at metafoo dot co.uk
2013-06-27 23:22 ` [Bug c++/57745] " paolo.carlini at oracle dot com

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).