C ++ 11 gcc: explicit qualification in declaration? Standart room?

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

extern int i; int ::i; int main() { } 

gcc complains that:

 error: explicit qualification in declaration of `i` 

Is this inappropriate behavior? Where in the standard is this program considered poorly formed?

8.3p1 seems to indicate that it should be allowed:

If the qualifier is the global scope resolution operator, the declaration identifier is the name declared in the global namespace scope.

Update:

From N3485 8.3p1:

The list of declarators appears after the optional (section 7) decl-specifier-seq (7.1). Each declarator contains exactly one declaration identifier; he calls the declared identifier. The unqualified identifier found in the declarator, id should be a simple identifier, except for the declaration of some special functions (12.3, 12.4, 13.5), and for the declaration of typical specializations or partial specializations (14.7). When the declaration identifier is qualified, the declaration refers to a previously declared member of the class or namespace to which the qualifier refers (or, in the case of a namespace) to an element of the built-in namespace of this namespace (7.3.1) or their specialization; a member is not just entered using a declaration in the scope of a class or namespace nominated by a declarator-id identifier naming clause. The nested qualifier name of the qualified identifier declarator shall not begin with the decltype qualifier. [Note: if the qualifier is the global scope resolution operator, the declaration identifier is the name declared in the global namespace. - end note] The optional qualifier-seq attribute following the declarator identifier is a declared object.

+6
source share
2 answers

And the very following sentence says (in n3337):

A declarator identifier should not be qualified , with the exception of defining a member function or a static data member outside its class, defining or explicitly instantiating a function or variable member of a namespace outside its namespace, or defining explicit specialization outside its namespace or declaring a friend, which is a member of another class or namespace.

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

+12
source

GCC is right under C ++ 11. In C ++ 14 this will be allowed. See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#482

+4
source

Source: https://habr.com/ru/post/950667/


All Articles