Please consider the following C++20 program:
void (*p)(int x);
void f(auto x) {
p = f;
}
int main() {
f(4.2);
}
Is this ill-formed? What I would have expected to happen is that f(4.2)
instantiates f
as void(double)
, and so the assignment of p to f should be a type mismatch. But, g++ accepts this without warning.
What am I missing?
Update
For reference, the following program:
void (*p)(int x);
void g(double x);
int main() {
p = g;
}
fails with error: invalid conversion from void (*)(double)
to void (*)(int)
question from:
https://stackoverflow.com/questions/65950064/assignment-of-function-template-instantiation-to-function-pointer 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…