Reputation: 60268
As stated in namespace.std#6:
Let F denote a standard library function ... Unless F is designated an addressable function, the behavior of a C++ program is unspecified (possibly ill-formed) if it explicitly or implicitly attempts to form a pointer to F. ...
Which means for the following program:
#include <cctype>
auto f = &std::tolower; // bad
the behavior is unspecified, and the program is possibly ill-formed. (std::tolower
is not an addressable function).
However, is the following program well-formed and/or is the behavior specified?
#include <cctype>
using u = decltype(&std::tolower); // good?
Here, the forming of the pointer to the function is done in an unevaluated context, and so it seems reasonable that I could just get the type of the function pointer. In this case, I expect u
to just be int (*) (int) noexcept
. Is this valid?
Upvotes: 2
Views: 142
Reputation: 40013
The intent is that this is invalid. The point of the rule is to allow implementations to do things like add parameters with default arguments or provide additional overloads. These things, done properly, are invisible to calls of the function but misbehave when the function itself is examined—especially if the overloads cause there to be no singular “itself”. None of this has to do with evaluation: it happens during overload resolution for the function name.
That said, the wording could be clearer: the mixed descriptions of compile- and run-time behavior confuse the question as to whether the evaluation of the identity of the function is what is problematic.
Upvotes: 7