title: Calling friend function defined in struct requires forward declaration?
body: <p>While reading Karlsson's <em>Beyond the C++ Standard</em> the author defined the friend function <strong>intrusive_ptr_add_ref</strong> in the body of <strong>class reference_counted</strong> (see pg 36).  That function is called automatically using Argument Dependent Lookup at the proper time.</p>
  
  <p>Never having seen friend functions defined in the body of a class, I played around and discovered that gcc 4.4.3 requires a forward declaration if not using ADL lookup.  In fact, there seems to be no way to reference <strong>adl_no</strong> without that forward declaration.  Is this part of the C++ standard or is it an artifact of gcc? (I don't have Windows box so cannot try VC).</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  
  namespace {
      void adl_no();        // Remove this and it won't compile with gcc
  
      struct Q {
          friend void adl_yes(const Q&amp;) {
              std::cout &lt;&lt; "adl_yes" &lt;&lt; std::endl;
          }
  
          friend void adl_no() {
              std::cout &lt;&lt; "adl_NO" &lt;&lt; std::endl;
          }
      };
  }
  
  
  int main(int argc, char** argv)
  {
      adl_yes(Q());
      adl_no();
  
      return EXIT_SUCCESS;
  }
  </code></pre>