ldc executable crashes with this code
Steven Schveighoffer
schveiguy at gmail.com
Thu Feb 3 13:13:52 UTC 2022
On 2/3/22 12:53 AM, forkit wrote:
> But @safe or not, nothing good can come from casting an immutable string
> to a mutable string, and the compiler really should know that ;-)
>
If you have a function that accepts mutable data, but you know for that
call it won't mutate the data (or maybe it's a C function that never
mutates the data, but isn't attributed with const/immutable), then it is
not UB.
It's only UB to cast away immutable/const *and* mutate it.
Reference: https://dlang.org/spec/const3.html#removing_with_cast
-Steve
More information about the Digitalmars-d-learn
mailing list