Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 gcc: explicit qualification in declaration? Standard ref?

Tags:

c++

gcc

c++11

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 non-conformant behaviour? Where in the standard is this program deemed ill-formed?

8.3p1 seems to indicate that it should be allowed:

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

Update:

From N3485 8.3p1:

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.

like image 417
Andrew Tomazos Avatar asked Jul 30 '13 22:07

Andrew Tomazos


2 Answers

And the very next sentence says (in n3337):

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.

like image 127
jrok Avatar answered Nov 11 '22 23:11

jrok


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

like image 4
Johannes Schaub - litb Avatar answered Nov 11 '22 21:11

Johannes Schaub - litb