[cfe-dev] "using namespace" seemingly not effective

Florian Weimer fweimer at redhat.com
Sun May 12 00:47:34 PDT 2013


clang++ (default flags, trunk version) does not grok the following code:

namespace outer {
   void f(int &);
   void g();
   namespace inner {
     void f(long &);
   }
}

void
outer::g()
{
   using namespace outer::inner;
   int i;
   f(i);
   long l;
   f(l);
}

t.cpp:16:3: error: no matching function for call to 'f'
   f(l);
   ^
t.cpp:2:8: note: candidate function not viable: no known conversion from 
'long' to 'int &' for 1st argument
   void f(int &);
        ^

I find this rather odd, considering that there is an explicit "using 
namespace" directive.  I'm not sufficiently familiar with the C++ name 
lookup rules, but I could have understood if f(int &) became invisible. 
  But the other way round is very surprising.

-- 
Florian Weimer / Red Hat Product Security Team



More information about the cfe-dev mailing list