I have a template class NB::B<T> derived from a non-template class NA::A in a namespace. act<T> is a template function calling add_ref function on an instance of its template argument. Specifically, act<NB::B<int>> wants to find add_ref defined in the namespace of NB::B's base using ADL. The complete example is following:

template<class T>
void act() {
  T* p = 0;
  add_ref(p); // the failing line
}

namespace NA
{
  struct A { };

  // I want ADL to find this:
  void add_ref(A* p) {
  }
}

namespace NB
{
  // template class with non-template base
  template <class T>
  struct B: NA::A { };

  typedef B<int> Bi;

  // using NA::add_ref; // fixes the problem
}

int main()
{
  act<NB::Bi>();
}

This compiles okay in gcc (4.7.0). And in Comeau online. However clang (3.1) fails:

a.cpp:4:3: error: use of undeclared identifier 'add_ref'

At the same time, the standard reads:

3.4.2/2 …

— If T is a template-id, its associated namespaces and classes are the namespace in which the template is defined; for member templates, the member template’s class; the namespaces and classes associated with the types of the template arguments provided for template type parameters (excluding template template parameters); the namespaces in which any template template arguments are defined; and the classes in which any member templates used as template template arguments are defined.

Surprisingly, template's bases aren't listed as paths to associated namespaces. Thus clang's behavior appears to be correct. And Comeau and gcc are accepting incorrect program.

At the same time, 3.4.2/3 states that using's in argument's names

Edit
Report