From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B43D33858C53; Tue, 13 Sep 2022 12:27:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B43D33858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663072061; bh=EAQkWH8I5hfOmiTXVI48i3skNqriDwlOXoYmDXR/mGg=; h=From:To:Subject:Date:From; b=x6lrX0Rbxg6vAt7BIlYLO6URLe0z2RTN/OB77Rw+7UyQvMIuA243XG0VzZN3MSxz6 lQ9EzROGMsPGcsHSei+uzfOvrTz47WbF0Tu6KENu0c0EVWznrlADm8JorvaHzr6OAP KVDPXNU6oncx+runn+7nYTAe6Yt3RUr1eFvXIlQU= From: "jzwinck at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106926] New: string_view construction from literal string containing null/zero should warn Date: Tue, 13 Sep 2022 12:27:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jzwinck at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D106926 Bug ID: 106926 Summary: string_view construction from literal string containing null/zero should warn Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jzwinck at gmail dot com Target Milestone: --- This code compiles but does something the programmer almost certainly does = not want: #include constexpr std::string_view sv =3D "four\0nine"; // 9 bytes of data static_assert(sv.size() =3D=3D 4); // required by C++, but surprising GCC can't implement what the programmer intended, so it should warn if a string_view is constructed or assigned from a string literal which contains null bytes before the end. When this happens, the rest of the string literal data is still accessible = but only if you know it's there by some other means. I expect such usage to be very rare, so warning about it even at -Wall seems reasonable. Even if the warning only comes with -Wextra that would be better than silence.=