This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/56568] std::initializer_list return value contents lost prematurely


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]