I wrote the following program that compiles with msvc but rejected by clang and gcc. It uses explicit object member function. Demo.
#include <iostream>
struct C{
int f(this int);
};
decltype(C::f) func; //msvc accepts but clang and gcc rejects
int func(int j)
{
std::cout << "called with: " << j << std::endl;
return 5;
}
As you can see msvc accepts this program but gcc says:
<source>:7:13: error: invalid use of non-static member function 'int C::f(this int)'
7 | decltype(C::f) func;
| ^
<source>:7:13: error: invalid use of non-static member function 'int C::f(this int)'
<source>:7:13: error: invalid use of non-static member function 'int C::f(this int)'
|
<source>: At global scope:
<source>:13:15: error: 'int func(int)' redeclared as different kind of entity
13 | int func(int j)
| ^
<source>:7:16: note: previous declaration 'int func'
7 | decltype(C::f) func;
| ^~~~
I want to know if this is well-formed or ill-formed etc as per the c++ standard.