Conflicting extern variable declarations

Skip to first unread message

Anders Granlund

Jul 15, 2015, 3:00:08 PM7/15/15


Consider the following program:

int main() {
extern int x;
extern double x;

Trying to compile it with different compilers, seem to suggest that it is
ill-formed. This also seems reasonable.

However I started to wonder what the c++ standard has to say about this.
This is what I observed:

At first, it looks like it's a violation of [basic.scope.declarative]/4:

Observe however the following note there:

These restrictions apply to the declarative region into which a name is
introduced, which is not necessarily the same as the region in which the
declaration occurs.

Now let's have a look at [basic.scope.pdecl]/11:

There we can read the following:

"Function declarations at block scope and variable declarations with the
extern specifier at block scope refer to declarations that are members of
an enclosing namespace, but they do not introduce new names into that

This seem to suggest that [basic.scope.declarative]/4 doesn't apply here.
Any thoughts?

[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: ]

Reply all
Reply to author
0 new messages