namespace aliasing problem
Helmut Jarausch
jarausch@IGPM.Rwth-Aachen.DE
Tue Sep 29 04:56:00 GMT 1998
Forwarding a reply to my question to comp.lang.std.c++
Nathan Myers<ncm@cantrip.org> writes
Helmut Jarausch<jarausch@numa1.igpm.rwth-aachen.de> wrote:
>How clever is a compiler required to be concerning 'identical'
>using declarations? I couldn't find anything the CD2 draft which
>decides what's correct in the following example
>
>namespace standard // this will occur with 'std' quite often
>{ void print(int) {};
> void dump(int) {};
>}
>namespace A { using standard::print; }
>namespace B { using namespace standard; }
>namespace User
>{ using namespace standard; // most typical usage of 'using directive'
> using namespace A;
> void test()
> { print(1); } // egcs-1.1: call of overloaded `print (int)' is ambiguous
>}
>namespace User2
>{ using namespace standard;
> using namespace B;
> void test()
> { print(1); } // egcs has no problems here
>}
>
>The aliases standard::print and B::standard::print are identical.
>Is the compiler required to recognized that?
>If not, isn't that a severe problem with 'using directives' ?
>If the example in 'User2' should be correct, doesn't this force me
>to prefer 'using directives' over 'using declarations' ?
This is a bug in Egcs. All aliases of a name refer to a single
declaration, and cannot overload one another. Only the original
declaration referred to is "real".
In particular, using-declarations don't affect Koenig lookup.
For example, in
namespace A {
struct X {};
void f(X*);
};
namespace B {
using A::X;
void g(X*);
}
int main() {
f((A::X*)0); // OK
g((B::X*)0); // error
}
the type X is defined in A, and not in B, so Koenig lookup
using the argument type locates A::f but not B::g. (Egcs
gets this right, anyway.)
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany
More information about the Gcc-bugs
mailing list