C ++ 11 gcc:声明中的显式限定条件?标准参考? [英] C++11 gcc: explicit qualification in declaration? Standard ref?

查看:893
本文介绍了C ++ 11 gcc:声明中的显式限定条件?标准参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当下面的C ++ 11程序用gcc 4.7编译时:

When the following C++11 program is compiled with gcc 4.7:

extern int i;
int ::i;

int main()
{
}

gcc抱怨:

error: explicit qualification in declaration of `i`

这是不符合行为吗?

8.3p1似乎表示应该允许:

8.3p1 seems to indicate that it should be allowed:


如果
限定符是全局:: scope解析运算符,则declarator-id引用在全局
命名空间范围中声明的名称。

If the qualifier is the global :: scope resolution operator, the declarator-id refers to a name declared in the global namespace scope.

更新:

来自N3485 8.3p1:

From N3485 8.3p1:


在可选(第7条)decl-specifier-seq(7.1)之后出现一个声明列表。每个声明器包含
正好一个declarator-id;它命名被声明的标识符。在声明符
id中出现的非限定id应该是一个简单的标识符,除了一些特殊函数(12.3,12.4,13.5)的声明和模板特化或部分特化的
声明(14.7 )。当declarator-id被限定时,
声明将引用限定符
引用的类或命名空间的先前声明的成员(或者在命名空间的情况下,是指该命名空间的内联命名空间集(7.3.1))
或其特殊化;该成员不应仅仅由在声明者id的嵌套名称说明符指定的类或命名空间范围内的使用声明
引入。限定的declarator-id的
nested-name-specifier不能以decltype-specifier开头。 [注意:如果
限定符是global :: scope解析运算符,那么declarator-id是指在全局
命名空间范围中声明的名称。 - end note] declarator-id之后的可选属性说明符seq属于
被声明的实体。

A list of declarators appears after an optional (Clause 7) decl-specifier-seq (7.1). Each declarator contains exactly one declarator-id; it names the identifier that is declared. An unqualified-id occurring in a declarator- id shall be a simple identifier except for the declaration of some special functions (12.3, 12.4, 13.5) and for the declaration of template specializations or partial specializations (14.7). When the declarator-id is qualified, the declaration shall refer to a previously declared member of the class or namespace to which the qualifier refers (or, in the case of a namespace, of an element of the inline namespace set of that namespace (7.3.1)) or to a specialization thereof; the member shall not merely have been introduced by a using-declaration in the scope of the class or namespace nominated by the nested-name-specifier of the declarator-id. The nested-name-specifier of a qualified declarator-id shall not begin with a decltype-specifier. [ Note: If the qualifier is the global :: scope resolution operator, the declarator-id refers to a name declared in the global namespace scope. — end note ] The optional attribute-specifier-seq following a declarator-id appertains to the entity that is declared.


推荐答案

下一句话(在n3337中):

And the very next sentence says (in n3337):


除了在
类之外的成员函数或静态数据成员的定义外,除了
之外的一个命名空间的函数或变量成员的定义或显式实例化之外,id不应该被定义 b命名空间,或者在其命名空间之外定义显式专门化,或者声明一个
friend函数,该函数是另一个类或命名空间的成员。

A declarator-id shall not be qualified except for the definition of a member function or static data member outside of its class, the definition or explicit instantiation of a function or variable member of a namespace outside of its namespace, or the definition of an explicit specialization outside of its namespace, or the declaration of a friend function that is a member of another class or namespace.

在异常中未提及全局变量的定义。

A definition of a global variable is not mentioned among the exceptions.

这篇关于C ++ 11 gcc:声明中的显式限定条件?标准参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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