I've recently come across Can I take the address of a function defined in standard library? and was shocked by the fact that the answer is fundamentally No. I surely have written &std::someTemplClass<SomeConcreteType>::someMember in a few places at least, so I should review all of them, but how do I go about it?
From the relevant piece of the standard,
[…] Unless
Fis designated an addressable function, the behavior of a C++ program is unspecified […]
it feels like I have to search the standard for all the std::stuff to which I've applied & and look for the words "addressable function".
But how can I be sure I've looked at the correct page for a given std::stuff?
The linked answer surely makes two examples, but I still have some doubts.
For instance:
Moreover, the behavior of a C++ program is unspecified (possibly ill-formed) if it attempts to form a reference to
For if it attempts to form a pointer-to-member designating either a standard library non-static member function ([member.functions]) or an instantiation of a standard library member function template.
Does this mean that a standard library non-static member function and an instantiation of a standard library member function template are never an addressable function?
If that's the case, am I correct to understand that any occurrence of &std::someTemplClass<SomeConcreteType>::someNonStaticMemberFunc or even just &std::someClass::someMemberFunc passed to a higher order function, such as in these cases,
doStuff(someRange | ranges::views::filter(&std::optional<int>::has_value));
std::transform(v.begin(), v.end(),
w.begin(),
boost::bind( &std::string::c_str, boost::placeholders::_1 ) );
is wrong?
And what about it being in unevaluated context, e.g. decltype(&std::someTemplClass<SomeConcreteType>::someNonStaticMember)?
Please, don't tell me the answer is "you should read the standard end-to-end" :(
Cppreference has a list of addressable functions, and it contains only iostream manipulators.
I've checked the standard draft, and the only places where the word "addressable" appears (outside of its definition) are all here (so indeed only manipulators).
So yes, your examples are illegal.
Including in unevaluated context. The point of this rule is to be able to quietly add overloads and change their signatures, as long as the call syntax looks normal. If the function you pass to
decltype(&foo)ends up overloaded, you'll get a compilation error.