在C ++标准中,指定当“将”要求被违反? [英] In the C++ standard, what is specified to occur when a "shall" requirement is violated?

查看:161
本文介绍了在C ++标准中,指定当“将”要求被违反?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,着名的单词(§3.2/ 1)

For example, the famous words (§3.2/1)


无翻译单元应包含任何变量的多个定义,函数,类类型,枚举
类型或模板。

No translation unit shall contain more than one definition of any variable, function, class type, enumeration type, or template.

我相信应要求被解释为除非另有规定,否则它们隐含地后跟否则程序不成形。但是,其他人声称应该而是否则行为是未定义的。

I believe "shall" requirements are to be interpreted as though they are implicitly followed by "otherwise the program is ill-formed" unless otherwise specified. However, others claim that "shall" instead means "otherwise the behavior is undefined".

在每个案例中,我遇到了标准中的要求没有遵循否则行为是不确定的或无需诊断,它发生的规则是一个明显是可诊断的,并由我知道的所有编译器诊断(上面的例子)。这就是为什么我相信这意味着否则程序是错误的,,需要诊断。

In every case I've come across in the standard in which a "shall" requirement was not followed by something like "otherwise the behavior is undefined" or "no diagnostic required", the rule it occurred in was one that is obviously diagnosable and is diagnosed by all compilers I know of (the above paragraph being an example). That's why I believe it means "otherwise the program is ill-formed", i.e., a diagnostic is required.

无论如何,我的想法。

Anyway, those are just my thoughts. I'd appreciate an authoritative answer.

推荐答案

是的,为了形式良好,程序必须遵循单一定义规则您已在问题(§1.3.26)中引用:

Yes, to be well-formed, the program must follow the One Definition Rule that you've quoted in the question (§1.3.26):


完善的程序



根据语法规则,可诊断语义规则和单一定义规则(3.2)构建的C ++程序。

well-formed program

C++ program constructed according to the syntax rules, diagnosable semantic rules, and the One Definition Rule (3.2).

其他可诊断规则指定为(§1.4):

The other diagnosable rules are specified as (§1.4):


1.4实施合规性[intro.compliance]



1可诊断规则集由本国际标准中的所有句法和语义规则组成,但
除了包含无需诊断或描述的明确符号的规则作为导致未定义的行为。

2虽然本国际标准仅声明对C ++实现的要求,但如果将这些要求表述为对程序,程序的某些部分或执行的要求,这些要求通常更容易理解程式。这些要求具有以下含义:

- 如果程序不包含违反本国际标准中规则的行为,合格的实现应在其资源限制内接受并正确执行 2 该程序。

- 如果程序包含违反任何可诊断规则或本标准中描述的结构出现的情况为有条件支持

- 如果程序包含违反不需要诊断的规则,则本国际标准将对于该程序的实现没有要求。
[着重添加]

1.4 Implementation compliance [intro.compliance]

1 The set of diagnosable rules consists of all syntactic and semantic rules in this International Standard except for those rules containing an explicit notation that "no diagnostic is required" or which are described as resulting in "undefined behavior."
2 Although this International Standard states only requirements on C++ implementations, those requirements are often easier to understand if they are phrased as requirements on programs, parts of programs, or execution of programs. Such requirements have the following meaning:
— If a program contains no violations of the rules in this International Standard, a conforming implementation shall, within its resource limits, accept and correctly execute2 that program.
If a program contains a violation of any diagnosable rule or an occurrence of a construct described in this Standard as "conditionally-supported" when the implementation does not support that construct, a conforming implementation shall issue at least one diagnostic message.
— If a program contains a violation of a rule for which no diagnostic is required, this International Standard places no requirement on implementations with respect to that program.
[emphasis added]

是的,如第二个要点,如果违反了可诊断的规则,则需要诊断。

And yes, as noted in the second bullet point, if a diagnosable rule is violated, a diagnostic is required.

这篇关于在C ++标准中,指定当“将”要求被违反?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆