Problem with namespaces. global name crashes with namespace name
Dean Foster
foster@compstat.wharton.upenn.edu
Fri Apr 2 07:12:00 GMT 1999
// $Id:
// using egcs(g++) version:
// Reading specs from
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/specs
// gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
#include <iostream.h>
int f(); // same problem if defined here also
Two weeks ago I upgraded to egcs 1.0.3. I loved it. I reported a bug (that had
been fixed) and so upgraded to egcs 1.1.2. I'm loving it even more! I can now
write in real C++ instead of watered down C++.
In the process of moving to standard compilant code, I discovered the following
namespace bug. Suppose there is a global f() defined and an X::f() declared.
These names crash when I try to define X::f() without reopening the name space.
Personally, I'm kinda inclined to consider this a feature. :-) I hope never to
have such code in my production code.
thanks again for a wonderful compiler,
dean
// using egcs(g++) version:
// Reading specs from
// /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.66/specs
// gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
#include <iostream.h>
int f(); // same problem if defined here instead of later
namespace X
{
int f();
};
int
X::f() // this generates a name crash with int f() above: "ambiguates old
declariation `int f()'"
{
return 2;
};
// replacing the above defintion with the following works fine
//namespace X { int X::f() {return 2;} };
main()
{
cout << X::f() << endl;
};
int f()
{
return 1;
};
More information about the Gcc-bugs
mailing list