Why does taking the address of an inline friend not result in code being produced. This works for regular inline functions. Is the declaration not matching the inline friend somehow?
#include <iostream>
namespace S
{
template <unsigned N>
class X
{
int i;
friend X operator+(const X& a, const X& b) noexcept
{
(void)a;
(void)b;
return {};
}
};
inline X<256> operator+(const X<256>&, const X<256>&) noexcept;
}
int main()
{
S::X<256> (*ptr)(const S::X<256>& a, const S::X<256>& b) noexcept = &::S::operator+;
std::cout << (void*)ptr << std::endl;
return 0;
}
$ g++ --version
g++ (GCC) 11.2.1 20220401 (Red Hat 11.2.1-10)
$ g++ -std=c++17 test2.cpp
test2.cpp:18:13: warning: inline function ‘S::X<N> S::operator+(const S::X<N>&, const S::X<N>&) [with unsigned int N = 256]’ used but never defined
18 | inline X<N> operator+(const X<N>&, const X<N>&) noexcept;
| ^~~~~~~~
/usr/bin/ld: /tmp/ccoA1Nxj.o: in function `main':
test2.cpp:(.text+0xc): undefined reference to `S::X<256u> S::operator+<256u>(S::X<256u> const&, S::X<256u> const&)'
collect2: error: ld returned 1 exit status