Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Conflicting extern variable declarations

68 views
Skip to first unread message

Anders Granlund

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

Hi,

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:
http://eel.is/c++draft/basic#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:
http://eel.is/c++draft/basic#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
scope."

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 mailto:std-cpp...@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

0 new messages