https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102573

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to wjf from comment #2)
> Hi Andrew,
> 
> I know that adding "-fsanitize=address" could detect the
> stack-use-after-scope in runtime. But why not just delete the copy member in
> std::initializer_list implementation? I don't see much sense to permit the
> copy operation.

Because this is how std::initializer_list works.
Note even using LLVM's libc++ with clang produces the same runtime failure.



This is also why GCC has a warning at compile time explicitly for this case:
<source>: In function 'int main()':
<source>:9:19: warning: assignment from temporary 'initializer_list' does not
extend the lifetime of the underlying array [-Winit-list-lifetime]
    9 |     il = {111, 222};
      |                   ^

Reply via email to