<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57723>57723</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang incorrectly treats hidden `friend` function definitions as a member of the class for purposes of member access
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
strega-nil-ms
</td>
</tr>
</table>
<pre>
Hey all! Not sure if the title is correct/useful, but basically, given:
* `struct kitty`
* `struct puppy`, with a `friend kitty` declaration, and a private data member `x`
* `int get_x(puppy p)`, which is a hidden friend of `kitty`
`get_x` is allowed to access `puppy::x`, despite it not being a friend of `puppy`. Note that if `get_x` is defined out-of-line from `kitty`, it is not able to access `puppy::x`, and that MSVC and GCC correctly implement this.
### Examples
#### The bug
[godbolt link][bug]
```cxx
struct kitty;
struct puppy {
friend kitty;
private:
int x;
};
struct kitty {
friend int get_x(puppy p) {
return p.x;
}
};
```
#### Out-of-line definition of the `friend` function
[godbolt link][not-bug]
```cxx
struct kitty;
struct puppy {
friend kitty;
private:
int x;
};
struct kitty {
friend int get_x(puppy p)
};
friend int get_x(puppy p) {
return p.x;
}
```
[bug]: https://gcc.godbolt.org/z/rocdhvnYr
[not-bug]: https://gcc.godbolt.org/z/db1vnvse6
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVcmSmzAQ_Rq4qExhNBhz4ODxZJJLkkNSqcopJVADSgSiJOGx8_VpsXgbUkmuceFF6uW1-j21c8VP2Ts4ESalF63JB2WJ6TUQURJbA7HCSlwYUiitobBe9NwbKHt03pO8tyRnRhQYfHIblThA69GdFz554fwZ7Yi3CY3VfWHJD2HtCZdLtq7vusGGmV6ErQlzxlILaPk5kHAoJNPMCtU6R4Y2RjotDswC4cwy0kCTg3axx3sk0VpSgf129KLtAEc6L0pnzFoUtTsrI7XgHFoyYavSxd6VPn5uwjEdFuYCpVQvwIlVhBUFGOPixmNhU-juOCFxMJ3AcoUlLTY8B9FWiHoDN3cjcJwgETWzjpQ7RA6laBFR9XalypXEBaZRzU3BiIhI6O3AWI6E_qlA19UB8f2nL-Pq7X4_a0CeiGg6CQ1gN20tTHDLNx0f8ubInJu523emzyitvK8mS_xYKZ4raQnW_8OLn3DHWfHHba_Hpzgex50bTdHHa-drSREvmWwEXzd6moMm_Zyl6xydVo6XtMnTMsSQaBFiWWy3ru6lwfa6JV1wQXPbDvE19NyExZa71n68UsKgDuGuihOVu8_nC-X0U_ZtMdyj39OAiln9t1S8TvcPzC2wdmFskaWzqOmO1NZ2xp0xesanKopg6n2gdIU7P_GtVcHrQ_tVn-Ov2PjLHDxfH9qDgY0P2XqzoWEa0zj0eUZ5SlPmD_M920uGA0i0lwtuNTBr5jm4qJordeHkc1NzGryT1HBM43wplUbqdacMGGeZfMbp4_daZnfHwMHf50GhGlxIeZi_Vp1W38c_IGFMj1Mleo6TJKJ-nfGHvAz5lkLCcs5oGa0jSLYPZQIbDmmS-pLlIE2GHfSiqIUXMqTA39hJX2RRGEVhuqbrbRzHYUC3bBs-UFqEKdCEbryHEBomZODqcL31dTaUhFQYNEphrLkY8dSiagEGOMzPelsrnaFGoWKrVshVY_yhgGw4wC9hmkJJ">