public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106926] New: string_view construction from literal string containing null/zero should warn
@ 2022-09-13 12:27 jzwinck at gmail dot com
  2022-09-13 14:48 ` [Bug c++/106926] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jzwinck at gmail dot com @ 2022-09-13 12:27 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-16 14:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 12:27 [Bug c++/106926] New: string_view construction from literal string containing null/zero should warn jzwinck at gmail dot com
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

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).