[Issue 17287] [ICE] backend/cgcod.c 255: zero length static arrays

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Mar 30 07:38:40 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17287

ZombineDev <petar.p.kirov at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|accepts-invalid             |ice-on-valid-code
                 CC|                            |petar.p.kirov at gmail.com
           Hardware|x86                         |All

--- Comment #2 from ZombineDev <petar.p.kirov at gmail.com> ---
@Stefan It easily comes up in generic code when length is based on some
calculation and/or code generation via string mixins For reference see
http://docs.algorithm.dlang.io/latest/mir_ndslice_slice.html#Slice
and browse through the source code (https://github.com/libmir/mir-algorithm).

T[0] is pretty normal if you think about it as struct S { }. If passing around
structs without any members works, why wouldn't zero-sized static arrays be ok?
Structs without members are invalid in C, but on the contrary are quite common
in C++ and similarly D allows them for a reason. See also
http://en.cppreference.com/w/cpp/language/ebo,
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html and
http://dlang.org/spec/arrays.html:

> A static array with a dimension of 0 is allowed, but no space is allocated for it. It's useful as the last member of a variable length struct, or as the degenerate case of a template expansion.

--


More information about the Digitalmars-d-bugs mailing list