The following fails to compile on all MSVC, Clang and GCC:
struct SomeFoo;
SomeFoo myfuncReturningFoo() { return SomeFoo(); }
struct SomeFoo {};
int main()
{
SomeFoo ffoo = myfuncReturningFoo();
}
The error message is “return type ‘struct SomeFoo’ is incomplete”.
Now this:
struct SomeFoo;
template <typename convenient_dummy = char>
SomeFoo myfuncReturningFoo() { return SomeFoo(); }
struct SomeFoo {};
int main()
{
SomeFoo ffoo = myfuncReturningFoo();
}
Now this will compile on my MSVC. On further investigation it compiles on MSVC on Goldbolt if the -Wextra is not set (IS NOT SET), removing the -Wextra flag makes it compile. On Clang you can remove the -Wextra flag but it still doesn’t compile. Same as GCC. Removing the -Wextra flag makes it compile in the template version on MSVC.
What is making this happen?
1