<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58859>58859</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unable to friend a function with requires clause
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
danakj
</td>
</tr>
</table>
<pre>
The following code fails to compile in Clang but works in GCC and MSVC. The `requires` clause on the function is part of its signature and is required when referring to it in a friend statement, otherwise overload resolution could not succeed.
However the presence of the requires clause appears to make it impossible to have a friend expression work in Clang.
Godbolt: https://godbolt.org/z/xexcvWfch
```cpp
template <class T>
constexpr inline bool trait = true;
template <class T>
class S {
template <class U>
friend inline void friendly() noexcept
requires(trait<U>);
// Clang can't call this from friendly().
static void priv() {}
};
template <class T>
inline void friendly() noexcept
requires(trait<T>)
{
// Clang can't see the private function.
S<T>::priv();
}
int main() { friendly<int>(); }
```
```
<source>:19:11: error: 'priv' is a private member of 'S<int>'
S<T>::priv();
^
<source>:22:14: note: in instantiation of function template specialization 'friendly<int>' requested here
int main() { friendly<int>(); }
^
<source>:11:17: note: implicitly declared private here
static void priv() {}
^
1 error generated.
```
This is a C++20 issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVUGXozYM_jXm4tc8MElIDhxmmJ3tpaeZbc_GiOAdx6a2SWb211c2BLJp2u6--pFgISR9nyyJ2jQf5WsHtDVKmbPUBypMgyKXylFvUDr2UgGVmlaKo7oePD0b--bCo89VRblu6G8vv1crGvyQbWrhz0FacLilQvHBATWa-hBk0MJLFKSjPbeempZK76iTB839YCE6Q-XkoqHnDjRKLVgbsCEg6UNgymlrJeDbznMPR9CesIoajGLPMkQ8gVWGN2jsjBpiVGEG1VBtPHWDEADNiqRPJH0Y_381Z0CjCLRHK9ACAsAgXyhd-PC-B25jgo78DSKoY2-ckzXmCp92_AQLRngPDl3AEFI3J_O7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