skypjack skypjack - 1 month ago 7x
C++ Question

Is sizeof(void()) a legal expression?

From [5.3.3/1], I found that:

The sizeof operator shall not be applied to an expression that has function or incomplete type

From [3.9/5] I found that:

Incompletely-defined object types and cv void are incomplete types

Anyway, for
does not evaluate it's operands, I would have said that
was a legal expression (actually GCC compiles it and the result is 1).

On the other side, from here,
is not mentioned while discussing
, neither when the types having size 1 are mentioned, nor in the list of the ones having an implementation defined size.

The question is thus: is
a legal expression?

Is it guaranteed to have size equal to 1?

Or is it a legal expression resulting in an UB and that's all?


void() is a function type (it's a function which takes no arguments and returns nothing), so it's not a valid type in sizeof().