I found a problem concerning namespace search.
The following simplified code failed to compile:
namespace A {
namespace B {
class Test {
};
}
namespace C {
namespace B {
typedef B::Test AnAlias;
}
}
}
The compiler complains that Test in namespace A::C::B does not name a type.
The problem seems to be that the compiler sees a namespace B inside namespace C and does not no further search. I would have exspected that he also would look in namespace A (which is a enclosing namespace) and find the B::Test there.
If I rename C::B everything is fine.
If I qualify A::B::Test everything is fine.
If I put the typedef directly in namespace A::C everything is fine.
This behavior was tested with gcc 4.1 and intel 12 compiler. (both for linux).
Are the compilers right?
The
Bintypdef B::Testresolves toA::C::B. If you’re going to reuse the nameB, you need to specify it to remove the ambiguity. The compilers are behaving properly. IIRC, names are resolved to the closest declaration to its use or reference. In this caseA::C::Bis the closest declaration to thetypedef.