It looks like a compiler bug to me. In both cases, ADL should
kick in. In the first case, it looks in namespace A
,
including names in namespace A
that were only declared in
class a
, and finds A::swap
. In the second case, it looks in
the global namespace (since that is where b
is defined),
including names in the global namespace that were only declare
in class b
, and finds ::swap
.
Of course, it starts with unqualified name lookup, which will
only find C::swap in both cases. Apparently, C++Builder somehow
marks ::swap
as hidden in this case, and fails to consider it
in ADL. In the case of ADL, however, both the global namespace
and namespace A should be treated equally.
The full rules are in §3.4.2. It's pretty heavy going, but for simple cases like yours, the implications are clear.