Static and non-static member functions with the same parameter types cannot be overloaded. But if member functions are templates and one of them has requires
clause then all compilers allow it. But the problems appear when one calls both of the member functions:
struct A {
static int f(auto) { return 1; }
int f(auto) requires true { return 2; }
};
int main() {
[[maybe_unused]] int (A::*y)(int) = &A::f; // ok everywhere (if no below line)
[[maybe_unused]] int (*x)(int) = &A::f; //ok in GCC and Clang (if no above line)
}
If only one (any) line is left in main()
then GCC and Clang accept the program. But when both lines in main()
are present, Clang prints
error: definition with same mangled name '_ZN1A1fIiEEiT_' as another definition
and GCC reports an internal compiler error. Demo: https://gcc.godbolt.org/z/4c1z7fWvx
Are all compilers wrong in accepting struct A
definition with overloaded static and not-static member functions? Or they just have similar bugs in the calling of both functions.