[PATCH] PR17337 - Retain previous linkage of friend function declarations

Richard Smith richard at metafoo.co.uk
Wed Sep 25 08:18:08 PDT 2013


On Wed, Sep 25, 2013 at 6:23 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> > I'll also explain the reasoning behind our implementation, which is
> > borne of practical needs as much as correctness:
> >
> > Language linkage specifications can only appear at namespace scope
> > ([dcl.link]p4).
> >
> > So this is invalid:
> > class ... {
> >   friend extern "C" int bar(Foo *y);
> > };
> >
> > Therefore pre-declaring the desired language linkage and retaining it in
> > the friend declaration is the _only_ way to implement a friend function
> > with different language linkage to its declaration context.
>
> I think I agree. Even if this is not standard compliant, it seems a
> useful gcc/msvc extension and less crazy than other extensions we
> support.
>
> Richard, do you see a case where supporting this extension (assuming
> it is one) would break standard conformant code?


I'll give it some more thought, but I don't think so. I'm happy to support
this as an extension if not -- for me the most convincing case is something
like:

extern "C" int f();
extern "C++" int g();
struct S {
  friend int f();
  friend int g();
};

I think it's impossible for S to befriend both f() and g() with the current
behavior. (Though one might argue that you could factor out the
implementation of f() into a function that is not extern "C", so this isn't
necessarily a critical issue, but it is inconvenient.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130925/99e5226c/attachment.html>


More information about the cfe-commits mailing list