<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147177>147177</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Cannot declare friend function template with unqualified name in C++20 mode without prior forward declaration
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Fedr
</td>
</tr>
</table>
<pre>
This program
```c++
template <typename T>
class A {
friend void f<>(A);
};
template <typename T>
void f(A<T>) {}
int main() {
f(A<int>{});
}
```
is accepted in GCC and MSVC starting from C++20. But Clang keeps complaining:
```
error: no candidate function template was found for dependent friend function template specialization
3 | friend void f<>(A);
| ^
```
Online demo: https://gcc.godbolt.org/z/vKjhY9WMv
It looks related to ADL changes for function templates lookup with explicitly-specified template arguments in C++20: https://en.cppreference.com/w/cpp/language/adl.html#Notes
GCC and MSVC both allow unqualified names in template friend declaration `friend void f<>(A&);`, which is accepted if function template `f` is declared after class `A` body but before its instantiation.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE2PpDYQ_TXVl9K0aNN89IEDwyxRlGxyyCpRjsYuwLvGJrbpzuyvjwzMZGcmE62E1C2oV36v3itz79VgiCrI7iF7OPAljNZVLUl36Kx8rD6NyuPs7OD4BEkNebI9Ath9fJI60DRrHgghbcLjTIZPhJ8g_QBJLTT3HmuEIlYiIvZOkZF4tUpiD2kT61hZA7tAGmugeNj__H_nvUGEps36jl3WY4qHDaxMwIkrA6x8-rQz2EHKhAjbIN8e_43K2McjF4LmQBKVwR-aBrmR-PG33xv0gbugzIC9sxM220hYcsT7JWCjuRnwC9HsUdioRBllBkjrVyeQc9ZBWqOxKLiRSkbN_WJEUNbg8xRu3GNvFyOxtw4lzWQkmfA00rcAP5NQXKuvPL7f5acIRYPfY8VatFZD9uEV51-NVoZQ0mQj8zGE2UdlrAXWDkIcBys7q8PRugFY-xVYe_3p8_jn5Y-P182fHwNqa794dBTJSgwW64efUYzcDORXjW8k-RWzzHhTYUT6e9ZKqKAf71apvYptntRzNywTmeCjbc_evGVL5ijm2VFPjoygo7ATsPYGrBXzDKyNNi58IGAtl_o4hkkDS3-xkQ0k9YtAdDaMyLW2N1zMXwvXG6cY3JXGM7l99pKE5m61ByFP3nUk303JE2AN3kYlRnwRzP4_7I8NIU9i4XYOSeR9IIfbWkK-eopxz7FbAnbUW0eo1pH5wE1QK7UjJPVBVqm8pBd-oOpUZKeivBTl-TBWrGSMUZ5Lyk9U9rzsKEtPp_JU5jxNO35QFUtYlhRJnpSnnJ2PLM_6PGMZT3NGsiQ4JzRxpY9aX6cYmIPyfqHqdC5ORXHQvCPt1wuKMUM3XL8CY_G-clUE3XXL4OGcaOWD_7dNUEFT1XBjbHgawfvbskbqtWsvsoOTlVudXQLOTsWIWnfj7oWTh8Xp6tVGqDAu3R6tyG__uZud_UwiAGtXVR5Yu8u-VuyfAAAA__9PGsVd">