[Bug c++/106926] string_view construction from literal string containing null/zero should warn

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Sep 13 14:48:30 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106926

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Blocks|                            |87403
   Last reconfirmed|                            |2022-09-13
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Is this a real problem you've seen in the wild?

The same argument applies to std::string, doesn't it?

To generalise it, I think we would probably want a new attribute telling the
compiler that a character pointer argument will be passed to strlen, and only
that many bytes used (i.e. it's treated as a "null-terminated byte string" in
ISO C++ terminology). Then the compiler can warn if an argument to that
function has unreachable characters.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning


More information about the Gcc-bugs mailing list