From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D0EA23858C5F; Tue, 28 Mar 2023 09:28:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0EA23858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679995733; bh=MgShg9li+cPF4IJPG1mqEqr2hM6ZNlSwdAFJk5SKVaU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ech636+Lb3IyR6jSSFzQHMZVu1EOKcc9h1P3UgMEaShsteiD/YwPu27fonTv3zdtv AF4CRk+msfAzCxslJkMhJsqlJvW1/1Gz/PEkyveAWVqeVHPGBMHYIwq/5BX988vZRe MRuoo6EnGR+JcikcyJ+z9/fv1oTM7Scy3OYlD6JQ= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109299] [12/13 Regression] wrong warning on std::wstring with -O2 -std=c++20 -D_FORTIFY_SOURCE=2 Date: Tue, 28 Mar 2023 09:28:53 +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: 12.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109299 --- Comment #5 from Jonathan Wakely --- This is not a library bug. The library code is: basic_string(basic_string&& __str) noexcept : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator())) { if (__str._M_is_local()) { traits_type::copy(_M_local_buf, __str._M_local_buf, __str.length() + 1); } else { _M_data(__str._M_data()); _M_capacity(__str._M_allocated_capacity); } The warning is coming from the call to traits_type::copy which only happens= if the string fits in the local buffer. Warning that it overflows the buffer is not helpful when we don't take that branch BECAUSE IT WOULD OVERFLOW THE BUFFER. These warnings need to be removed from the compiler.=