Having read about the most vexing parse, I experimented a bit and found this program. There are two very similar lines. One of them yields warnings in both g++7 and clang++-3.9, another does not.
int main() {
void(); // no warning
int(); // warning: statement has no effect
}
In the second line a default-constructed object of type int
is created and immediately destroyed, thus unused. But what happens in the first line? If it was parsed the same way, it should be an error because it is illegal to create an object of type void
. On the other hand, it does not look like a function declaration as well.
void
is not a data type. It is used to declare different things in argumentsfunction a(void)
, returnsreturn void
and, of course, universal pointervoid *
. But it is a completely different thing thanint
. So, no wonder that compiler does different treatment for them. Though i would prefer it gives some warning in the first place as well. – Platitudevoid
is used to remove warning about unused variable. They probably treat this expression the same way. – Sluffvoid()
might also be used to avoid evil comma operator:(foo<Is>(), void(), 0)...
. – Sluff