title: GCC, Clang, and IBM disagree on how to perform template-parameter-dependent name lookup. Which one is right?
body: <p>Consider this example I found on IBM's website:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  void f(double) { cout &lt;&lt; "Function f(double)" &lt;&lt; endl; }
  
  template&lt;class T&gt; void g(T a) {
    f(123);
    h(a);
  }
  
  void f(int) { cout &lt;&lt; "Function f(int)" &lt;&lt; endl; }
  void h(double) { cout &lt;&lt; "Function h(double)" &lt;&lt; endl; }
  
  void i() {
    extern void h(int);
    g&lt;int&gt;(234);
  }
  
  void h(int) { cout &lt;&lt; "Function h(int)" &lt;&lt; endl; }
  
  int main(void) {
      i();
  }
  </code></pre>
  
  <p>What will it print?</p>
  
  <ul>
  <li><p>The IBM documentation I adapted this example from, available <a href="http://publib.boulder.ibm.com/infocenter/comphelp/v101v121/advanced/print.jsp?printType=singleTopicPrint&amp;linkId=t1_2_16_6" rel="noreferrer">here</a>, says it will print:</p>
  
  <pre><code>Function f(double)
  Function h(double)
  </code></pre>
  
  <p>The rationale for this is that template-parameter-dependent name lookup is performed right before the instantiation of <code>i()</code>, so it finds <code>h(double)</code> but not <code>h(int)</code>. </p></li>
  <li><p>When I compile it using GCC 4.4.1, it prints:</p>
  
  <pre><code>Function f(double)
  Function h(int)
  </code></pre>
  
  <p>GCC seems to be looking up the template-parameter-dependent names in the template after everything else has been compiled, so it finds both <code>h(double)</code> and <code>h(int)</code>, and prefers the latter.</p></li>
  <li><p>When I compile it using Clang 2.8, it fails to compile. The compiler error is:</p>
  
  <pre><code>ibm_example.cc:8:3: error: use of undeclared identifier 'h'
    h(a);
    ^
  ibm_example.cc:16:3: note: in instantiation of function template specialization 'g&lt;int&gt;' requested here
    g&lt;int&gt;(234);
    ^
  1 error generated.
  </code></pre>
  
  <p>Clang seems to be looking up the template-parameter-dependent names in the template at the point where the template is declared, so it finds neither <code>h(double)</code> nor <code>h(int)</code>.</p></li>
  </ul>
  
  <p>Which one is right?</p>