[Bug c/116082] -Wunterminated-string-initialization should not warn about strings that end with "\0" but should warn still for -Wc++-compat
alx at kernel dot org
gcc-bugzilla@gcc.gnu.org
Thu Jul 25 09:56:21 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116082
--- Comment #3 from Alejandro Colomar <alx at kernel dot org> ---
(In reply to Alejandro Colomar from comment #2)
> I agree with martin.
>
> And what if the '\0' is in the middle of the literal?
>
> char x[4] = "a\0b";
> char x[3] = "a\0b";
> char y[2] = "a\0b";
>
> I'd keep it simple, and assume the \0s in the middle of a string literal are
> not our business as far as this diagnostic is concerned. If we cannot write
> the implicit null byte, diagnose.
On the other hand, we could say that any string literals that have an explicit
\0 are invalid strings, as a string is defined as a sequence of zero or more
non-zero bytes followed by exactly one zero byte. Since that string literal is
not a really string, this diagnostic could be omitted.
More information about the Gcc-bugs
mailing list