阵的评价范围绑定静态数据成员的 [英] Scope of evaluation of array bound of static data member

查看:128
本文介绍了阵的评价范围绑定静态数据成员的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要提出针对海湾合作委员会的错误,但后来意识到,如果标准我间pretation是正确的,这是一个核心语言的缺陷,而不是一个编译器错误。

I was going to file a bug against GCC, but then realized that if my interpretation of the Standard is correct, it's a core language defect, not a compiler bug.

当数组类型的静态数据成员以外类范围内定义,势必在阵列中标识符在类范围内抬头。

When a static data member of array type is defined outside class scope, identifiers in the array bound are looked up in class scope.

§9.4.2[class.static.data]说:在一个静态数据成员的定义的初始化前pression是同类产品(3.3.7)的范围,但不说有关声明符本身的东西。看来,这是一个声明符中唯一的名称查找环境。

§9.4.2 [class.static.data] says "The initializer expression in the definition of a static data member is in the scope of its class (3.3.7)," but doesn't say anything about the declarator itself. It seems that this is the only name lookup context within a declarator.

§8.4.2[dcl.array]没有提及阵列的范围限制,所以默认恩pression在封闭范围,这是命名空间进行评价。

§8.4.2 [dcl.array] doesn't mention the scope of the array bound, so by default the expression is evaluated in the enclosing scope, which is the namespace.

class X {
  static int const size = some_complicated_metafunction<>::value;
  static int arr[ size ];
};

// "size" should be qualified as "X::size", which is an access violation.
int X::arr[ size ] = {};

问题是,如果绑定的数组类范围不评估,就没有办法访问私有类成员和 some_complicated_metafunction&LT;&GT; 将不得不respecified。约束阵列需要的同一范围内的初始化,对于本质上是相同的理由,初始化。 (虽然不是很强劲,因为不断的前pressions总是可以重新计算,不像私​​有对象的地址。)

The problem is that if the array bound is not evaluated in class scope, there is no way to access private class members, and some_complicated_metafunction<> would have to be respecified. The array bound needs the same scope as the initializer, for essentially the same reason as the initializer. (Although not quite as strong, since constant expressions can always be recomputed, unlike the address of a private object.)

我缺少的东西或者是为了灾难恢复?

Am I missing something or is a DR in order?

推荐答案

我觉得在一个成员定义绑定的数组是类范围。 3.3.7标准/ 1:

I think the array bound in a member definition is in class scope. Standard 3.3.7/1:

如下规则描述了在类中声明的名称的范围。

The following rules describe the scope of names declared in classes.

...

5)延伸到或过去的类定义的最后声明的潜在范围也延伸到其成员的定义限定的区域,即使成员在类的外部词汇定义(包括静态数据成员的定义,嵌套类定义,成员函数定义(包括成员函数体和这样的定义哪些的声明符部分的任何部分如下声明符-ID ,包括一个参数声明,条款及任何默认参数( 8.3.6)。...

5) The potential scope of a declaration that extends to or past the end of a class definition also extends to the regions defined by its member definitions, even if the members are defined lexically outside the class (this includes static data member definitions, nested class definitions, member function definitions (including the member function body and any portion of the declarator part of such definitions which follows the declarator-id, including a parameter-declaration-clause and any default arguments (8.3.6). ...

下面的说明符-id为 X ::改编

Here the declarator-id is X::arr.

这篇关于阵的评价范围绑定静态数据成员的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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