title: What are the rules for using qualified names in friend declarations?
body: <p>The following code produces a compile error (on a recent version of gcc at least):</p>
  
  <pre><code>namespace a {
  
  class X { friend void ::foo(); };
  
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>'void foo()' should have been declared inside '::'
  </code></pre>
  
  <p>If we remove <code>::</code> from the declaration, according to the standard, <code>foo</code> will be introduced into the namespace <code>a</code> (although it won't be visible). Predeclaring foo inside of <code>a</code> is not required.</p>
  
  <p>My question is, given the above, why is predeclaring within the global namespace a requirement? Why doesn't the name <code>foo</code> become a member of the global namespace? I couldn't find any paragraph in the standard that would explicitly forbid that either, so I'm curious to know.</p>