In a related question it's said that there's no such thing as a pointer to non-member const function. In addition, C++11 8.3.5/6 says
The effect of a cv-qualifier-seq in a function declarator is not the same as adding cv-qualification on top of the function type. In the latter case, the cv-qualifiers are ignored. [ Note: a function type that has a cv-qualifier-seq is not a cv-qualified type; there are no cv-qualified function types. —end note ]
If I understand it correctly, this means that there's no such thing as a non-member const function. (Although such functions are not const, they cannot be modified as per 3.10/6). In particular, pointers to const function are meaningless.
However, it seems that some compilers do create pointers to const function in type deduction contexts. For instance, consider the code:
#include <iostream>
void f() {}
template <typename T> void g( T*) { std::cout << "non const" << std::endl; }
template <typename T> void g(const T*) { std::cout << "const " << std::endl; }
int main() {
g(f);
}
When compiled with GCC and Intel the code outputs "non const" as I would expect from the quote above. However, the output is "const" when compiled with Clang and Visual Studio.
Is my interpretation correct?
Update:
Following the comments, I'm trying to clarify that I'm not talking about const member functions. I'm interested in non-member functions (but the same arguments probably apply to non-static member functions as well). I've also changed the question title to make it more precise.
Consistent with the resolution of g(f)
mentioned above, the line below is ilegal for GCC and Intel but not for Clang and Visual Studio
const auto* ptr = &f;
Update 2:
I agree with Andy Prowl's interpretation and have selected his answer. However, after that, I was made aware that this question is a CWG open issue.
void g(T*) const;
signature of a class member. The question is different though .. – πάντα ῥεῖ