<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71595>71595</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[17 regression][C++20] templated friend not working if the concept use contains the enclosing friend
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
regression
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zero9178
</td>
</tr>
</table>
<pre>
Recently upgraded to Clang 17 which lead to code that previously worked in Clang 16 to suddently stop compiling. I have reduced it to the following snippet:
```cpp
template <class T, class U>
concept Test = true;
class UnwindFrame
{
template <Test<UnwindFrame> F>
friend void unwindStack();
UnwindFrame();
};
template <Test<UnwindFrame> F>
void unwindStack()
{
auto u = UnwindFrame();
}
int main()
{
unwindStack<int>();
}
```
https://godbolt.org/z/1vcqeGnG1
When using Clang 17 or newer the `friend` declaration seemingly has no effect causing a compilation failure due to the use of a private constructor:
```
<source>:16:14: error: calling a private constructor of class 'UnwindFrame'
16 | auto u = UnwindFrame();
| ^
<source>:21:5: note: in instantiation of function template specialization 'unwindStack<int>' requested here
21 | unwindStack<int>();
| ^
<source>:10:5: note: implicitly declared private here
10 | UnwindFrame();
| ^
```
This used to work in Clang 16 and is valid C++20 I believe.
While reducing, I noticed the following important properties for this to be reproducible: `unwindStack` HAS to be restricted by a concept and the concept HAS to be templated, with a template parameter being the enclosing class `UnwindFrame` in this case.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVc1y4joTfRqx6RrKlrCNFywIhPmy_Sa37lrIbbvvCMkjyVDJ09-SDATyc2umKhX_0H101OfoWHpPnUFcseKBFduZHENv3eoVna3zajnb2-Zl9X9UaIJ-gXHonGywgWBho6XpIK_g1JPqQaNMr5VtEEIvAwwOj2RHr1_gZN1PbIDMpauMpX5smgnXBzuAsoeBNJluDk_QyyOCw2ZUsS_E8tAjtFZreyLTgTc0DBiYWLNsy7I1K7Pp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