According to cppreference since C++23
For a non-static non-virtual member function not declared with cv-qualifier or ref-qualifier, its first parameter, if not being a function parameter pack, can be an explicit object parameter (denoted with the prefixed keyword
this
).
Can this parameter be of type void
? Current compilers allow it, but diverge in calling of such member function:
struct A {
void f(this void) {}
};
// ok everywhere
auto p = &A::f;
int main() {
// ok in GCC and MSVC
p();
// ok in Clang
A{}.f();
}
Clang rejects p();
with the
error: called object type ‘void (A::*)()’ is not a function or function pointer
And GCC does not like A{}.f();
because
note: candidate expects -1 arguments, 0 provided
As well as MSVC:
error C2660: ‘A::f’: function does not take 0 arguments
Online demo: https://gcc.godbolt.org/z/zMaqaTTav
Which compiler is correct here?