<div dir="ltr">On Wed, Apr 24, 2013 at 7:14 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 24 April 2013 21:25, Weiming Zhao <<a href="mailto:weimingz@codeaurora.org">weimingz@codeaurora.org</a>> wrote:<br>

> Hi Rafael,<br>
><br>
><br>
><br>
> Could you please check if the attached patch fixes the issue<br>
> (<a href="http://llvm.org/bugs/show_bug.cgi?id=15841" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=15841</a>) correctly?<br>
><br>
<br>
</div>I don't think this is the correct fix. getLanguageLinkageTemplate<br>
should follow the structure of [dcl.link]. I think the real problem is<br>
the context the friend function is getting.<br>
<br>
I went looking in the standard, and what I found was [namespace.memdef] p3:<br>
<br>
-------------------------------------------<br>
Every name first declared in a namespace is a member of that<br>
namespace. If a friend declaration in a non-local class first declares<br>
a class, function, class template or function template the friend is a<br>
member of the innermost enclosing namespace.<br>
------------------------------------------<br>
<br>
If I read that correctly,<br>
<br>
extern "C" {<br>
  class Foo {<br>
    friend void bar();<br>
  };<br>
  void bar() {<br>
  }<br>
}<br>
<br>
is equivalent to<br>
<br>
void bar();<br>
extern "C" {<br>
  class Foo {<br>
    friend void bar();<br>
  };<br>
  void bar() {<br>
  }<br>
} <br>
<br>
So I now think that clang is correct and the code should be rejected.<br>
Richard, do you agree? Is this a defect?</blockquote><div><br></div><div style>The governing rule is [dcl.link]p4: "[...] In a linkage-specification, the specified language linkage applies to [...] function names with external linkage [...] declared within the linkage-specification."</div>
<div style><br></div><div style>"declared within" here is a lexical notion, and the friend function is declared within the linkage-specification.</div><div style><br></div><div style>(Later in that paragraph, we have "A C language linkage is ignored in determining the language linkage of the names of class members and the function type of class member functions", but since a friend isn't a member, that doesn't apply.)</div>
</div></div></div>