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.
source share