https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116780
--- Comment #17 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Georg-Johann Lay from comment #16)
> (In reply to Segher Boessenkool from comment #15)
> > It makes sense never, not on any target, not with LRA nor without.
> Though there are test cases that are UB and valid as I just
> learned some weeks ago.
But I am talking about *this* case, not about UB in general.
> To make a long story short, there are cases where GCC is handling UB in a
> predictable / testable way. Similar should be achievable with the test case
> in the current PR:
Hopefully. But the testcase as written is simply non-sensical. A better
testcase would be nicer.
> But on the other hand, ICEs don't look very professional...
Oh, I think most ICEs look very serious! :-)
> > It makes sense never, not on any target, not with LRA nor without.
>
> So ice-on-invalid-code then.
Yup.
> > It is incorrect according to 6.7.6.2/1 already ("If the expression is a
> > constant
> > expression, it shall have a value greater than zero.")
>
> Arrays of size zero are GNU-C addition.
Most testcases are also compiled without GNU extensions.
> But as far as I understand, when a
> zero-sized array doesn't occur in a structure, or when it is the only
> element in a struct, then accesses are invalid.
>
> https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
You can have zero-length arrays, but you cannot have any accesses to
non-existent objects (like any member of a length zero static array).