When compiling the following code with the compilation options "-std=c++17 -pedantic-errors" the compilation gives an error with gcc but no errors with clang (see compiler explorer links below). How is this possible? Is this undefined behaviour or does one of the compilers have a bug? Note that I am compiling with "-pedantic-errors" so the difference should not be because of a compiler extension.
template<typename T>
void f()
{
}
class C
{
friend void f<int>()
{
}
};
int main()
{
}
This is the compilation that gcc generates:
<source>:8:17: error: defining explicit specialization 'f<int>' in friend declaration
8 | friend void f<int>()
| ^~~~~~
<source>:8:17: error: ambiguating new declaration of 'void f()'
<source>:2:6: note: old declaration 'void f() [with T = int]'
2 | void f()
| ^