On Wednesday, 13 July 2016 at 10:02:58 UTC, Ola Fosheim Grøstad
wrote:
«Undefined» simply means that such code is not part of the
specified language, as in, it is no longer the language
covered. The optimizer is an implementation detail, the
optimizer is not allowed to change the semantics of the
language.
If casting away immutable is claimed to be undefined behaviour
it simply means that code that does this is not in the language
and the compiler could refuse to compile such code if it was
capable of detecting it. Or it _could_ specify it to have a
specific type of semantics, but that would be a new language.
You're confusing "undefined" with "implementation defined".
Implementation-defined stuff is something that's not specified,
but can be presumed to do *something*. Undefined stuff is
something that's officially considered to not even make sense, so
a compiler can assume it never happens (even though a programmer
can make the mistake of letting it happen). This is sometimes
controversial, but does let optimisers do some extra tricks with
sane code.