Patch for Friend function linkage check (PR 15841)

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Apr 24 19:14:36 PDT 2013


On 24 April 2013 21:25, Weiming Zhao <weimingz at codeaurora.org> wrote:
> Hi Rafael,
>
>
>
> Could you please check if the attached patch fixes the issue
> (http://llvm.org/bugs/show_bug.cgi?id=15841) correctly?
>

I don't think this is the correct fix. getLanguageLinkageTemplate
should follow the structure of [dcl.link]. I think the real problem is
the context the friend function is getting.

I went looking in the standard, and what I found was [namespace.memdef] p3:

-------------------------------------------
Every name first declared in a namespace is a member of that
namespace. If a friend declaration in a non-local class first declares
a class, function, class template or function template the friend is a
member of the innermost enclosing namespace.
------------------------------------------

If I read that correctly,

extern "C" {
  class Foo {
    friend void bar();
  };
  void bar() {
  }
}

is equivalent to

void bar();
extern "C" {
  class Foo {
    friend void bar();
  };
  void bar() {
  }
}

So I now think that clang is correct and the code should be rejected.
Richard, do you agree? Is this a defect?

Cheers,
Rafael



More information about the cfe-commits mailing list