The issue they are warning you about is that in C++14, this will work:
void call(void (*f)())
{
f();
}
void func() noexcept {}
int main(int argc, char* argv[])
{
call(&func);
return 0;
}
but in C++17, you would need to change the declaration of call
to be:
void call(void (*f)() noexcept)
{
f();
}
Since you have defined call
to be a template, you don't need to worry about this. Still, it could cause you problems because the inferred type is changing, which doesn't usually happen.
For example, this code will compile in C++14 but not C++17:
void foo() noexcept {}
void bar() {}
template <typename F>
void call(bool b, F f1, F f2)
{
if (b)
f1();
else
f2();
}
void foobar(bool b)
{
call(b, &foo, &bar);
}
In C++14, the types of foo
and bar
are the same, but they are different in C++17, meaning the template resolution will fail. The error message in gcc 7.2 with the flag -std=c++1z
is:
note: template argument deduction/substitution failed:
note: deduced conflicting types for parameter 'F' ('void (*)() noexcept' and 'void (*)()')
In the example you've given, there is no issue and you won't have a problem compiling in C++14 or C++17 mode. If the code is more complex than the example here (e.g. similar to the examples I gave above), you could encounter some compiler problems. It seems you have a recent compiler; try compiling with -std=c++1z
and see if there are warnings or errors.