The following C++ code: ######################################## class Klass { public: private: static void f(const char*& a, int b) {} }; int main (void) { char* x; Klass::f (x); } ######################################## Incorrectly produces the follow error message in GCC: main.cpp: In function ‘int main()’: main.cpp:13: error: no matching function for call to ‘Klass::f(char*&)’ main.cpp:7: note: candidates are: static void Klass::f(const char*&, int) This is not correct because f() is not a valid candidate because it's private and can never be called from outside of Klass. The purpose of this error message is to help the end user understand why his function call is not accepted by GCC (usually it's because one of the types are wrong in the parameter list, which is why the provided and candidate parameters are printed in the first place). However, in this context the fact that f is private is also highly relevant. Basically this is very confusing, GCC should mention that the only candidate is private and that's why stuff won't compile. Alternatively, GCC should not claim that f() is a candidate at all, because in reality it's not a candidate because it's not callable.
Access checking happens after overload resolution.
Namelookup is done before access control IIRC.
As stated in the comments the error message is strictly correct because overload resolution takes place before access checking. At the same time, I do agree that it might be helpful to mention the access level of each candidate in the error message if/when the access matters, similarly to what Clang does (below). On that basis I'll confirm this as an enhancement request. t.C:11:16: error: 'f' is a private member of 'Klass' Klass::f (x); ^ t.C:5:21: note: declared private here static void f(const char*& a, int b) {} ^ t.C:11:20: error: too few arguments to function call, expected 2, have 1 Klass::f (x); ~~~~~~~~ ^ t.C:5:9: note: 'f' declared here static void f(const char*& a, int b) {}