public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jzwinck at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-106926-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106926 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 <string_view> constexpr std::string_view sv = "four\0nine"; // 9 bytes of data static_assert(sv.size() == 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.
next reply other threads:[~2022-09-13 12:27 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-13 12:27 jzwinck at gmail dot com [this message] 2022-09-13 14:48 ` [Bug c++/106926] " redi at gcc dot gnu.org 2022-09-15 18:21 ` jzwinck at gmail dot com 2022-09-15 20:21 ` redi at gcc dot gnu.org 2022-09-16 14:24 ` jzwinck at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-106926-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).