<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Aug 11, 2014, at 2:49 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br><div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Aug 10, 2014 at 7:10 AM, Nicola Gigante <span dir="ltr"><<a href="mailto:nicola.gigante@gmail.com" target="_blank">nicola.gigante@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello.<br>
<br>
While testing a recently written piece of code to see if it worked on linux<br>
I found three differences between clang and g++ that make the first<br>
to compile the code and the second to reject it. I'm talking about the<br>
clang shipped with Xcode 5.1.1, I don't have a working trunk and my<br>
machine is slow to compile, sorry.<br>
<br>
Below the three issues:<br>
<br>
1) transitive-friend.cpp<br>
class A {<br>
  friend class B;<br>
  int v;<br>
};<br>
<br>
struct B {<br>
  A a;<br>
  friend int f(B b) {<br>
     return b.a.v;<br>
  }<br>
};<br>
<br>
Clang accept this code because<br>
I access the private field of A in the scope of B<br>
and B is a friend. g++ rejects it:<br>
<br>
$ g++-4.9 -std=c++11 -fsyntax-only differences.cpp<br>
differences.cpp: In function 'int f(B)':<br>
differences.cpp:3:7: error: 'int A::v' is private<br>
   int v;<br>
       ^<br>
differences.cpp:9:17: error: within this context<br>
      return b.a.v;<br>
                 ^<br></blockquote><div><br></div><div>Clang's behavior reflects the current intent of the C++ core working group. This is core issue 1699, and the current resolution to that is to treat everything that is lexically within a befriended entity as being befriended. GCC does not yet implement the resolution to core issue 1699 (which is reasonable, since it's not yet even resolved).</div></div></div></div></blockquote><div><br></div>Great, this is the best resolution.  There are many unfortunate corner cases not caught by the current wording, including nested classes within inline friend functions.</div><div><br></div><div>John.</div></body></html>