On Wednesday, 13 July 2016 at 10:25:55 UTC, sarn wrote:
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".
I am not confusing anything. A superset of a language is still
covering the language, but it is also a new language. I think you
are confusing "language" with "parsing".
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.
No. «Undefined» means exactly that, not defined by the language
specification, not part of the language. It does not say
anything about what should or should not happen. It is simply not
covered by the spec and a compiler could be compliant even if it
turned out rubbish for such code if the spec does not require the
compiler to detect all valid programs in the language. It has
nothing to do with optimisers, that's just an implementation
detail.
«Implementation defined» means that the implemented
compiler/interpreter _must_ define it in a sensible manner,
depending on the context, in order to comply with the spec.