This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/84587] [8 Regression] Local variable initializer goes out of scope since r247793
- From: "jason at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 27 Feb 2018 14:08:37 +0000
- Subject: [Bug c++/84587] [8 Regression] Local variable initializer goes out of scope since r247793
- Auto-submitted: auto-generated
- References: <bug-84587-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84587
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
The testcase has undefined behavior; the initializer_list array only lives
until the end of the initialization of 'a'.
11.6.4p6: The array has the same lifetime as any other temporary object (15.2),
except that initializing an initializer_list object from the array extends the
lifetime of the array exactly like binding a reference to a temporary.
15.2p6.9: A temporary object bound to a reference parameter in a function call
(8.5.1.2) persists until the completion of the full-expression containing the
call.
The code can be fixed by explicitly extending the initializer_list lifetime,
e.g.
std::initializer_list<const char> il = {'a', 'b', 'c'};
ArrayView<const char> a (il);