What I'm trying to do is create a template function that stores a generic function pointer and information about how to cast to it's actual type. This is being used by my script binding API to make C++ function calls from Python for a game engine. In the process of porting this to OSX using XCode4 with LLVM, I have run into an error. This sample code compiles and runs fine in Visual Studio 2012, but gives me the error "No matching function for call to 'Call'" with LLVM.
#include <iostream>
void testfun (int i)
{
std::cout << "Hello World " << i << std::endl;
}
typedef void BasicFunction ();
template <BasicFunction* fn, typename T0>
void Call (void(*f)(T0), T0 i)
{
reinterpret_cast<decltype(f)>(fn)(i);
}
int main(int argc, const char * argv[])
{
Call<reinterpret_cast<BasicFunction*>(testfun)>(testfun, 5);
return 0;
}
Is this non standard code? A bug with LLVM? Or is there just a better way to accomplish the same task? Note: The function pointer must come first in the template so that the function information can be deduced automatically.