首页 > 解决方案 > “语义违规不需要诊断”的理由是什么?

问题描述

后续问题:如果违反了“应/不应”要求,那么该要求位于哪个部分(例如语义、约束)是否重要?.

ISO/IEC 9899:202x (E) 工作草案——2020 年 12 月 11 日 N2596,5.1.1.3 诊断,1:

如果预处理翻译单元或翻译单元包含违反任何语法规则或约束的行为,则符合的实现应产生至少一个诊断消息(以实现定义的方式标识),即使该行为也明确指定为未定义或实现-定义。在其他情况下不需要生成诊断消息。

结果:语义违规不需要诊断。

问题:“语义违规不需要诊断”的(可能)理由是什么?

标签: clanguage-lawyerdiagnosticsstandards-compliancec17

解决方案


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!


推荐阅读