2015-06-11 05:07:31 UTC
the argument is evaluated. Taking that into account, I wonder what
should happen in this situation
int n = 42;
int (*a)[n] = NULL;
This is an example of a run-time evaluated 'sizeof'. However, formally
the argument contains a null-pointer dereference. Does this 'sizeof'
expression produce undefined behavior then? Or not?
Knowing the low-level idea behind VLA implementation, I understand that
run-time size of VLA is actually a piece of "sidecar" data that lives
besides the array, not embedded into the array itself. For this reason,
there are no material reason for the above expression to produce UB -
the 'sizeof' does not really need to access the array itself, it does
not really need to dereference the pointer.
However, the language spec says that the expression is evaluated, which
means that the potential for the UB is there. So, does it produce UB?
What was the intent?