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

Reply via email to