<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/77503>77503</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Invalid template friend declarations are accepted
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++,
clang:frontend,
accepts-invalid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Endilll
</td>
</tr>
</table>
<pre>
Consider the following example: https://godbolt.org/z/nP937n54a
```cpp
template <typename>
struct A {
template <typename>
struct B {
void foo();
};
};
class C {
int i;
// correct friend declaration
// template <typename T>
// template <typename U>
// friend class A<T>::B;
// incorrect friend declarations
template <typename T, typename U>
friend class A<T>::B;
template <typename T, typename U>
friend class A<T>::B<U>;
};
template <typename T>
template <typename U>
void A<T>::B<U>::foo() {
C c;
c.i = 0;
}
```
Clang accepts incorrect friend declarations that have only one template head, while 2 are required to refer to `B`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVN1u2zwMfRr6hmggy3_xhS8SpwG-u-9iewBZYmINiuRJcrru6QfbQZIWTYsBA4TEEg_JwyOKIgR9tEQNFFsodokYY-9882yVNsYknVOvTets0Io8xp7w4IxxL9oekX6J02AIsg32MQ4Bsg3wPfD90anOmbhy_gh8_xv43v5fZ5UtcgFsB2wDJVuWHIblJNJpMCISQtbG14GsOBFkz4sxRD_KiBuEarucIH7qgHhx2d67IJ6dVnhwDvgaeA3Z1QTV7rp78z3_SiNCwPY-lrYR9TsY4lI-Suc9yYgHr8kqVCSN8CJqZ98BPyoCv92V8Rnu-w13gV3yLXQ3kLVzqGwD2Wb7iKu2j9mGC_YBTd7iR2T-isY_Dd3O0Mf3-IXcX6g8N8-jnNPu2lj3jdKivOszudII2Q7ZG5Zv38Q949YIe0QhJQ0xfH5XGHsRsRdnQmfNKzpLN3V7EmoS9aXXhpCj8ISefo7ak8Lo0NNhet4OoWRbKNkqUU2m6qwWCTVpxfI15yVjSd-oshRFmrNOsrqQRSdJqTJdp3WaVut0XSe64YznLGV1WuV1Ua9KTpk4pFSmVKm8KyFndBLarIw5n6YZkegQRmqqqmBZYkRHJszTiHMJfDsvDryd9pMck9Le2UhWXQ0XhZ60PQuj5_Nil_hmSvHUjccAOTM6xHBLGnU01Py3ONyU-kjZSa0lA6lk9KZ5N-507MduJd0J-H6Kf_l7Grz7QTIC388VBuD7ucg_AQAA__-aips2">