I'm trying to find out whether the following code is valid (even if dubious in appearence)?
void hello(int, int) {}
int main() {
int a = 1;
int b = 2;
a == b
? hello(a, b)
: void();
return 0;
}
I have not found anything suggesting this would be invalid, and it compiles fine on clang and gcc. Questions I could find on SO were about void()
in the context of decltype here and sizeof here. It seems to mean different things in different contexts. If it is valid, I would like to know:
- What exactly does
void()
evaluate, if it does that at all, to? Can it be treated the same as an effectless void function call? Justvoid
, in this use case, gives me a compiler error. - Why is it not possible to simply omit one side of the ternary conditional?