N3936第3.3.7 / 1节中的规则3是否冗余? [英] Is rule 3 in section 3.3.7/1 from N3936 redundant?
问题描述
我最近回答了一个问题,涉及违反草案C ++ 14标准:N4140 节 3.3.7
> 段落 1 $
b $ b
I recently answered a question dealing with a violation of draft C++14 standard: N4140 section 3.3.7
Class scope paragraph 1
rule 2
which says:
在S类中使用的名称N在其
上下文中引用相同的声明,并在S的完成范围内重新求值。No $ b $违反此规则需要诊断。 $3
A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule.
< c>也似乎相关,它说:
at the time rule 3
also seemed relevant and it says:
如果重新排序类中的成员声明产生一个备用的有效
程序在)和(2),程序是错误的,没有诊断是
需要。
If reordering member declarations in a class yields an alternate valid program under (1) and (2), the program is ill-formed, no diagnostic is required.
我的初步反应是,规则 3
似乎是多余的,只是对规则 2
的澄清,并不包括任何未被覆盖的案例。导致交替有效程序的重新排序也必须违反规则 2
My initial reaction is that rule 3
seems redundant and is really just a clarification of rule 2
and does not cover any cases not already covered. A reordering that results in a alternate valid program would also have to violate rule 2
.
推荐答案
根据这些规则,到缺陷报告1875:在类作用域中重新排序声明规则 3
是多余的,建议的解决方案是删除规则 3
,它说:
According to Defect Report 1875: Reordering declarations in class scope rule 3
is redundant and the proposed solution is to remove rule 3
, it says:
规则#3的需要不清楚;看起来任何
否则有效的重新排序将不得不违反规则#2以便
产生不同的解释。从字面上来看,规则#3也将$ b $ b适用于简单地重新排序非静态数据成员,没有名称
依赖。是否可以简单删除?
The need for rule #3 is not clear; it would seem that any otherwise-valid reordering would have to violate rule #2 in order to yield a different interpretation. Taken literally, rule #3 would also apply to simply reordering nonstatic data members with no name dependencies at all. Can it be simply removed?
建议的解决方案是:
删除3.3.7 [basic.scope.class]段落1的第三项,
对后续项重新编号
Delete the third item of 3.3.7 [basic.scope.class] paragraph 1 and renumber the succeeding items
虽然这个缺陷报告似乎证实了我最初的怀疑,但我仍然有一种ging叨的感觉,或许规则 3
毕竟有点宽。 3.3.7
包括以下示例:
Although this defect report seems to confirm my initial suspicious I am left with a nagging feeling that perhaps rule 3
is bit broader after all. Section 3.3.7
includes the following example:
enum { i = 1 };
class X {
char v[i]; // error: i refers to ::i
// but when reevaluated is X::i
int f() { return sizeof(c); } // OK: X::c
char c;
enum { i = 2 };
};
违反规则 2
c $ c> 3 但小的调整:
which violates both rule 2
and 3
but a small tweak:
enum { i = 1 };
class X {
enum { i = 2 };
char v[i]; // no longer refers to ::i
// but reordering can cause it to refer to ::i again
int f() { return sizeof(c); } // OK: X::c
char c;
};
似乎不再违反规则 2
肯定违反规则 3
。我认为这个代码示例是麻烦的,因为成员的重新排序很容易导致代码回溯违反规则2,但没有诊断需要指示这使得这个代码相当脆弱。
seems to no longer violate rule 2
but sure seems to violate rule 3
. I would consider this code example to be troublesome since a reordering of the members could easily cause the code to be back in violation of rule 2 but no diagnostic is required to indicate this which makes this code rather fragile.
更新
据我理解规则 3
不适用于Casey在注释中提到的这个例子:
As far as I understand rule 3
does not apply to this example mentioned by Casey in the comment:
class X { int a; int b; };
,因为即使有多个有效排序,这种情况也不属于 1
和 2
其中规则 3
需要:
because even though there is more than one valid ordering this case does not fall under both rule 1
and 2
which rule 3
requires:
(1)和(2)下的备用有效程序
alternate valid program under (1) and (2)
这篇关于N3936第3.3.7 / 1节中的规则3是否冗余?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!