将函数指针 reinterpret_cast 与 void(*)() 进行比较是未定义的行为吗?

Is it undefined behavior to compare function pointers reinterpret_cast to void(*)()?

例如,我可以制作一个std::set<void(*)()>并使用reinterpret_cast将任意函数指针放入其中吗?我显然不能调用它们,但是如果我想记住我见过的函数,seen.count(reinterpret_cast<void(*)()>(fn)) 会是定义的行为吗?现在我假设我关心的函数没有超载。

这很好。根据 [expr.reinterpret.cast],

A function pointer can be explicitly converted to a function pointer of a different type.

它还说将函数指针转换为不同的函数指针类型并返回将产生原始指针类型。