Difference between Undefined Behavior and Ill-formed, no diagnostic message required

The standard is not always as coherent as we would like, since
it is a very large document, written (in practice) by a number
of different people, and despite all of the proof-reading that
does occur, inconsistencies slip through. In the case of
undefined behavior (and errors in general), I think there is an
additional problem in that for much of the most basic things
(pointers, etc.), the C++ standard inspires from C. But the
C standard takes the point of view that all errors are undefined
behavior, unless stated otherwise, where as the C++ standard
tries to take the point of view that all errors require
a diagnostic, unless stated otherwise. (Although they still
have to allow for the case where the standard omits to specify
a behavior.) I think this accounts for a lot of the
inconsistency in the wording.

Globally, the inconsistency is regrettable, but on the whole, if
the standard says that something is erroneous, or ill-formed,
then it requires a diagnostic, unless the standard says that it
doesn’t, or that it is undefined behavior. In something like
ill-formed; no diagnostic required“, the “no diagnostic
required
” is important, because otherwise, it would require
a diagnostic. As for the difference between “ill-formed; no
diagnostic required” and “undefined behavior”, there isn’t any.
The first is probably more frequent in cases where the code is
incorrect, the second where it is a run-time issue, but it’s not
systematic. (The specification of the one definition
rule—clearly a compile time issue—ends with “then
the behavior is undefined”.)

Leave a Comment