This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/56568] std::initializer_list return value contents lost prematurely
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 04 Sep 2015 09:02:06 +0000
- Subject: [Bug c++/56568] std::initializer_list return value contents lost prematurely
- Auto-submitted: auto-generated
- References: <bug-56568-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56568
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to fuzzyTew from comment #4)
> I'm not as experienced in the details. I think perhaps my example is
> invalid as you state but the original testcase is not (see &&).
That makes no difference. Using my previous example, David's original testcase
is roughly equivalent to:
const int& f() {
long i = 0;
return i;
}
auto&& i = f();
It's irrelevant what you do with the result, f() returns a dangling reference
to an object that doesn't exist after the function returns.
(In reply to David Krauss from comment #5)
> I'm working on an ISO proposal (http://bit.ly/genlife) to fix some such
> cases in C++17, but all it would do for return values is allow the compiler
> to produce a warning. The way initializer_list works, the sequence is
> intrinsically incapable of escaping the current scope, much less the current
> function.
Right.
I opened PR 67445 to suggest a warning for cases like this, but I don't expect
it to be implemented any time soon.