I understand that a template cannot appear inside an extern "C" block, the reason for which is that the name of the instantiated template functions cannot appear once than once using an unmangled name.
However, in the code below, the name of the function is being mangled (so there should be no problem because each instantiation will have a unique name) but still has function type with C language linkage. My question is whether the code below is well formed:
extern "C" using fn_type = void();
template<typename T>
fn_type foo;
int main()
{
fn_type* const p = foo<int>;
p();
}
Edit: it is hard to test if this is conforming just by running it through a compiler because GCC, Clang and MSVC don't distinguish between C++ and C function pointer types.
extern "C"function pointers.extern "C"block conflates the name and the type. Template functions cannot be declared in anextern "C"block because the name of every instantion would be the same. However, intemplate<typename T> fn_type foo;the name is being mangled (so there should be no problem because each instantiation will have a unique name) but the type should still have C language linkage. There's a good answer on this site explaining the difference between how language linkage affects names and types independantly but I'm struggling to find it.