如果违反了 "shall / shall not" 要求,那么该要求位于哪个部分(例如语义、约束)是否重要?

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

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

提问原因:本意见:

This is in a Semantics section of the standard, not Constraints, so no diagnostic is required.

是否违反语义部分中的“不得/不得”要求不需要诊断?

语义违规不需要诊断消息,而约束违规则需要。

关于诊断的 C11 standard 第 5.1.1.3p1 节规定如下:

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.

该标准仅非常松散地定义了“语义”的实际含义。最重要的是,标准的第 3 术语、定义和符号 中没有术语的定义。

标准 在该部分中定义的是“约束”的含义:

3.8

1 constraint

restriction, either syntactic or semantic, by which the exposition of language elements is to be interpreted

添加了对“...或语义”的强调。

标准接着说:

4. Conformance

1 In this document, "shall" is to be interpreted as a requirement on an implementation or on a program; conversely, "shall not" is to be interpreted as a prohibition.

2 If a "shall" or "shall not" requirement that appears outside of a constraint or runtime-constraint is violated, the behavior is undefined.

然后我们来到:

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.

添加了对“...或约束”的强调。

根据 3.8,“仅”是 语义限制 并不排除某些东西是 约束

根据 4. 1),“应”为要求,“不得”为禁止。

我将两者解释为表示约束。

根据5.1.1.3,不仅违反语法规则,而且违反约束需要诊断,即使(根据4. 2))“[... ] 行为也明确指定为未定义或实现定义。"


不过要注意,以免误会:

我在这里指的是语义在标准中用“应该”/“不应”指定不是任何语义任何程序。