From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 36714385841D; Sun, 3 Oct 2021 06:20:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36714385841D From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102573] optimized code removes the underlying elements of the std::initializer_list being copied Date: Sun, 03 Oct 2021 06:20:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 4.8.5 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Oct 2021 06:20:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102573 --- Comment #3 from Andrew Pinski --- (In reply to wjf from comment #2) > Hi Andrew, >=20 > I know that adding "-fsanitize=3Daddress" 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: : In function 'int main()': :9:19: warning: assignment from temporary 'initializer_list' does n= ot extend the lifetime of the underlying array [-Winit-list-lifetime] 9 | il =3D {111, 222}; | ^=