From [5.3.3 / 1], I found that:
The sizeof operator does not apply to an expression that has a function or partial type
From [3.9 / 5] I found that:
Incomplete object types and cv void are incomplete types
In any case, for sizeof does not evaluate its operands, I would say that sizeof(void()) is a legal expression (in fact, GCC compiles it, and the result is 1). On the other hand, from here , void not mentioned when discussing sizeof , neither when the types with size 1 are mentioned, nor in the list that have a specific implementation size.
The question arises: is there sizeof(void()) legal expression?
Is the size guaranteed to be 1?
Or is it a legal expression leading to UB and that is all?
c ++ language-lawyer sizeof void
skypjack Sep 01 '16 at 18:05 2016-09-01 18:05
source share