I am playing with online c++ compilers a little bit on link. But the code snippet below got failed when compiled with msvc v19.latest.
#include <iostream>
#include <cmath>
#include <cstdio>
template<class F, class...L>
void test(F f, L...args) {
std::cout<< "res = " << f(args...) << '\n';
}
int main()
{
test(cos, 0.1); #1
test(printf, "%s", "aaa"); #2
}
How could it be that line #2 is ok and line #1 can't get a pass?
MSVC is happy with the following code but this time it's GCC's turn to reject it. MSVC's iostream file includes cmath header and GCC #undefs cos :)
#include <stdio.h>
#include <math.h>
//#include <iostream>
template<class F, class...L>
void test(F f, L...args) {
f(args...);
}
int main()
{
test(cos, 0.1);
test(printf, "%s", "aaa");
}
Since c++20, there's another issue raised in the second answer and has been addressed in this question link