According to cppreference.com, C++20 introduces the "addressing restriction" for standard library functions:
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 }
Why was this introduced?
Especially with regard to backwards compatibility of the language, this seems to be a change that breaks a lot of existing code. What benefit does this provide that makes worth such a breaking change?