Topic: Weird wording
Author: shirarenai@yandex.ru
Date: Tue, 7 Apr 2009 10:57:37 CST Raw View
The wording is indeed weird. The intention of the authors of the
standard is not clear and compilers process differently the following
example:
namespace N1
{
int x;
}
namespace N2
{
int x;
}
using namespace N1;
using namespace N2;
void g ()
{
extern int x;
}
MSC-2005 reports an error, Comeau reports success (obviously seeing no
relation between g's x and N1::x or N2::x).
> However, it's known that no class member can be redeclared outside its
> class definition and thus such block-scope declarations are meaningless
> when applied to class members so it's not clear what the forbidding
> sentence should mean.
>
Meaningless or not, but it corresponds to the standard, and it hardly
was intended.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Ivan A. Kosarev" <ik@unicals.com>
Date: Wed, 8 Apr 2009 10:51:14 CST Raw View
shirarenai@yandex.ru wrote:
>
> using namespace N1;
> using namespace N2;
>
> void g ()
> {
> extern int x;
> }
Strictly speaking, both the names "x" are declared outside of the
innermost namespace scope.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Ivan A. Kosarev" <ik@unicals.com>
Date: Tue, 31 Mar 2009 15:35:58 CST Raw View
3.5 #6 reads:
"The name of a function declared in block scope, and the name of an
object declared by a block scope extern declaration, have linkage. If
there is a visible declaration of an entity with linkage having the same
name and type, ignoring entities declared outside the innermost
enclosing namespace scope, the block scope declaration declares that
same entity and receives the linkage of the previous declaration. If
there is more than one such matching entity, the program is ill-formed.
Otherwise, if no matching entity is found, the block scope entity
receives external linkage."
The only case I see when there is more than one such matching entity is
visible is the following:
class A { static int i; };
class B { static int i; };
class C : A, B {
void f() {
extern int i; // here
}
};
However, it's known that no class member can be redeclared outside its
class definition and thus such block-scope declarations are meaningless
when applied to class members so it's not clear what the forbidding
sentence should mean.
Are there other cases when there is more than one such matching entity
is visible?
Also, shall the types, say, "int[]" and "int[5]" be considered to be
"the same type" in this context? I mean, can such a declaration complete
the type of a previously declared array?
Consider this:
extern int a[];
int f()
{
extern int a[5]; // (f1)
return sizeof(a); // (f2)
}
int x()
{
return sizeof(a); // (x)
}
int g()
{
extern int a[5]; // (g1)
return sizeof(a); // (g2)
}
int y()
{
return sizeof(a); // (y)
}
int h()
{
extern int a[10]; // (h1)
return sizeof(a); // (h2)
}
What each of the marked lines should result into?
Is there an implementation that handles all this correctly?
Many thanks,
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]