title: ADL in case of equal-named member function
body: <p>The situation is that some member function <code>bar::Bar::frobnicate</code> wants to utilize ADL to find a function from some unknown namespace, within a function that has an identical name. However, it only finds its own name.</p>
  
  <h2>Testcase</h2>
  
  <p>(<em>Note</em> that in reality, <code>Bar</code> is a <code>Foo</code>-agnostic template; this is just the reproducible, minimal testcase)</p>
  
  <pre><code>namespace foo {
      struct Foo {};
      void frobnicate(Foo const &amp;) {}
  }
  
  namespace bar {
      struct Bar {
          void frobnicate() {
              foo::Foo foo;
              frobnicate(foo); // &lt;-- error
          }
      };
  }
  
  int main () {
      bar::Bar x;
      x.frobnicate();
      frobnicate(foo::Foo());
  }
  </code></pre>
  
  <p>Results in:</p>
  
  <pre><code>test.cc: In member function ‘void bar::Bar::frobnicate()’:
  test.cc:10:31: error: no matching function for call to ‘bar::Bar::frobnicate(foo::Foo&amp;)’
  test.cc:10:31: note: candidate is:
  test.cc:8:18: note: void bar::Bar::frobnicate()
  test.cc:8:18: note:   candidate expects 0 arguments, 1 provided
  </code></pre>
  
  <h2>Standard</h2>
  
  <p>I understand that this is correct compiler behaviour:</p>
  
  <blockquote>
    <h3>3.4.1 Unqualified name lookup <em>[basic.lookup.unqual]</em></h3>
    
    <p>(...) name lookup ends as soon as a declaration is found for the name (...)</p>
  </blockquote>
  
  <p>and only <em>after</em> unqualified lookup failed, argument dependent lookup comes into play:</p>
  
  <blockquote>
    <h3>3.4.2 Argument-dependent name lookup <em>[basic.lookup.argdep]</em></h3>
    
    <p>When the postfix-expression in a function call (5.2.2) is an unqualified-id, other namespaces not considered
    during the usual unqualified lookup (3.4.1) may be searched</p>
  </blockquote>
  
  <h2>Workaround</h2>
  
  <p>My current workaround is to introduce a special traits class that does not define the clashing name itself:</p>
  
  <pre><code>    struct BarTraits {
          void frobnicate_(foo::Foo const &amp;b) {
              frobnicate(b);
          }
      };
  </code></pre>
  
  <p>or this ligher version:</p>
  
  <pre><code>    void frobnicate_(foo::Foo const &amp;c) { frobnicate(c); }
  </code></pre>
  
  <h2>Question</h2>
  
  <p>Are there better alternatives than introducing such traits classes?</p>
  
  <p>Explicitly qualifying the call as <code>foo::frobnicate(foo)</code> is not an option here, because (as mentioned) the <code>Bar</code> class is a template upon <code>Foo</code> in reality and should not only work for types in the <code>foo</code> namespace.</p>