This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/57745] New: missing recursive lifetime extension within std::initializer_list
- From: "richard-gccbugzilla at metafoo dot co.uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 27 Jun 2013 23:08:21 +0000
- Subject: [Bug c++/57745] New: missing recursive lifetime extension within std::initializer_list
- Auto-submitted: auto-generated
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.