On Sunday, 15 November 2015 at 14:54:51 UTC, Andrei Alexandrescu wrote:
On 11/15/2015 09:34 AM, Dicebot wrote:
On Sunday, 15 November 2015 at 14:23:05 UTC, Jonathan M Davis wrote:
As I mentioned, he's okay with changing the language to make the
casts well defined. -- Andrei

Well, that's a big change, since it pretty much means that D's const isn't physical const anymore, and Walter has been _very_ insistent about that in the past - to the point that he's argued that C++'s const is outright useless because it isn't physical const. If casting away const and mutating is well-defined behavior, then we basically
have C++'s const except that it's transitive ...

Casting away _const_ is already legal if programmer can himself
guarantee underlying object has mutable origin (i.e. not available via immutable reference), by the very definition of const. It is casting
away immutable and mutating that is strictly UB.

Correct. I'm not sure whether that's clarified in the language documentation yet. -- Andrei

Quite the opposite in fact. Walter recently approved an update to the spec which clarified that it _is_ undefined behavior to cast away const and mutate even if the object being referred to isn't immutable underneath the hood:

https://github.com/D-Programming-Language/dlang.org/pull/1047

And from what I've seen, Walter has always been adamant that D's const is physical const and that casting away const and mutating is undefined behavior, arguing that if it weren't, it would be like C++'s const and that C++'s const is pretty much useless, because it doesn't provide actual guarantees. So, if he's now willing to have casting away const and mutating be well-defined behavior, that's a big shift.

- Jonathan M Davis

Reply via email to