Date: Fri, 06 Feb 2026 15:06:19 -0800
On Friday, 6 February 2026 14:05:57 Pacific Standard Time Sebastian Wittmeier
via Std-Proposals wrote:
> In B I did not mean the view to do the modification, but if the underlying
> storage changes, and the final NUL byte vanishes, we at least would know,
> how far we can read the string without UB.
I'd say it's as UB as changing the string a std::string_view points to and no
different than removing the NUL terminator of a regular C string. We can
declare it's out of scope.
> Optionally we could demand that the last byte of the underlying storage
> stays a NUL byte as sentinel.
The last byte of a cstring_view is part of the storage it refers to, even if
it is not part of the string itself. It must not change any more than any of
the other bytes.
> Even if the string ends with NUL earlier.
It doesn't end earlier. It ends at exactly the first NUL, which must remain
there.
via Std-Proposals wrote:
> In B I did not mean the view to do the modification, but if the underlying
> storage changes, and the final NUL byte vanishes, we at least would know,
> how far we can read the string without UB.
I'd say it's as UB as changing the string a std::string_view points to and no
different than removing the NUL terminator of a regular C string. We can
declare it's out of scope.
> Optionally we could demand that the last byte of the underlying storage
> stays a NUL byte as sentinel.
The last byte of a cstring_view is part of the storage it refers to, even if
it is not part of the string itself. It must not change any more than any of
the other bytes.
> Even if the string ends with NUL earlier.
It doesn't end earlier. It ends at exactly the first NUL, which must remain
there.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Data Center - Platform & Sys. Eng.
Received on 2026-02-06 23:06:30
