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: unassig...@gcc.gnu.org ReportedBy: ja...@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; }