clanguage-lawyerdiagnosticsstandards-compliancec17

What is the rationale for "semantics violation does not require diagnostics"?


Follow-up question for: If "shall / shall not" requirement is violated, then does it matter in which section (e.g. Semantics, Constraints) such requirement is located?.

ISO/IEC 9899:202x (E) working draft— December 11, 2020 N2596, 5.1.1.3 Diagnostics, 1:

A conforming implementation shall produce at least one diagnostic message (identified in an implementation-defined manner) if a preprocessing translation unit or translation unit contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined. Diagnostic messages need not be produced in other circumstances.

Consequence: semantics violation does not require diagnostics.

Question: what is the (possible) rationale for "semantics violation does not require diagnostics"?


Solution

  • A possible rationale is given by Rice's theorem : non-trivial semantic properties of programs are undecidable

    For example, division by zero is a semantics violation; and you cannot decide, by static analysis alone of the C source code, that it won't happen...

    A standard cannot require total detection of such undefined behavior, even if of course some tools (e.g. Frama-C) are sometimes capable of detecting them.

    See also the halting problem. You should not expect a C compiler to solve it!