Though the question seems a little bit confusing. The code is simple as:
template <typename T>
void tfunc(T&& getter)
{
}
template <typename T = void>
void voidfunc()
{}
int main() {
tfunc(&voidfunc); // error: could not deduce template argument for 'T'
tfunc(&voidfunc<int>); // ok
voidfunc(); // calling using default template parameter is ok.
}
Both clang 11& msvc visual studio 2019 16.7 complains error. Why I need to explicitly specify a template argument?
Background
- the argument is a dummy parameter just to delay the instantiation of
voidfuncto where it is used. The type doesn't really matter. &voidfuncis used by some code generated by clangAST, otherwise I need to tweak the generator to write&voidfuc<>if it is a template.__declspec(property(put=voidfunc))this clang/msvc extension however takesvoidfuncbut notvoidfunc<>
I've tweaked the generator to output &voidfunc<> as @Jarod42 says, if the given function is a template. And it works for now.