For C legacy reasons, the following definitions in C++ are equivalent:
void foo() {}
void foo(void) {}
What happens when foo is in a templated class ? For example:
template <typename T> struct C { void foo(T) {} };
int main()
{ C<void> c;
c.foo();
}
MSVC (19.30) accepts this code, but gcc (11.2) rejects it.
It seems that compilers disagree as to whether foo(T)
is equivalent to foo()
when T = void
.
Which is correct ?