Addressing restriction
The behavior of a C++ program is unspecified (possibly ill-formed) if it explicitly or implicitly attempts to form a pointer, reference (for free functions and static member functions) or pointer-to-member (for non-static member functions) to a standard library function or an instantiation of a standard library function template, unless it is designated an addressable function (see below).
Following code was well-defined in C++17, but leads to unspecified behaviors and possibly fails to compile since C++20:
#include <cmath> #include <memory> int main() { auto fptr0 = &std::betaf; // by unary operator& auto fptr1 = std::addressof(std::betal); // by std::addressof auto fptr2 = std::riemann_zetaf; // by function-to-pointer implicit conversion auto &fref = std::riemann_zetal; // forming a reference }
为什么要引入这个?
特别是考虑到语言的向后兼容性,这似乎是一项破坏了许多现有代码的变化。这提供了什么好处,使得这种破坏性的变化值得实施呢?