Consider the following snippet:
int main() {
struct Local {
virtual void foo() = 0;
};
void (Local::* ptr)() = &Local::foo;
}
When compiling with C++20, GCC 13.3.0 and Clang 18.1.3 both compile this code, but MSVC 19.39 thru 19.43 generate the following compiler error:
<source>(3): error C3640: 'main::Local::[thunk]: __cdecl `int __cdecl main(void)'::`2'::Local::`vcall'{0,{flat}}' }'': a referenced or virtual member function of a local class must be defined
I could not find anything in the C++20 standard to prove either compiler right. Is the code snippet well-formed?
A pure virtual function need be defined only if called with, or as if with (11.4.7), the qualified-id syntax (7.5.4.3).But you are not callingLocal::foohere, so I'd say your code is fine. Having said that, you can make msvc happy by adding a definition forLocal::foo(see [demo]).(godbolt.org/z/3rq4jqrTn)).virtual void foo() = 0 {}unlike other compilers: gcc.godbolt.org/z/dr8nh8nfn