[Bug 18] New: int foo[0] accept -- what's its semantics?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 5 16:30:56 PST 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=18

           Summary: int foo[0] accept -- what's its semantics?
           Product: D
           Version: 0.148
          Platform: Macintosh
               URL: http://www.digitalmars.com/drn-
                    bin/wwwnews?digitalmars.D.bugs/6444
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: walter at digitalmars.com
        ReportedBy: braddr at puremagic.com


void main() {
    int foo[0];
}

dmd 0.148 accepts this gdc 0.17 and my 0.18 work in progress both segv off in
gcc land where it's assumed that variables passed into the middle end all have
space associated with them.  What are the right semantics for this situation? 
I can fix gdc's interaction with the gcc internals, but I want to make sure I
understand what it really means first.

Pushing the code a little:
     1  void main(){
     2      int i[0];
     3      int *j = &i;
     4      int *k = &(i[0]);
     5      return 0;
     6  }
$ dmd -g -c /tmp/junk.d
/tmp/junk.d(3): cannot implicitly convert expression (& i) of type int[0]* to
int*
/tmp/junk.d(4): array index [0] is outside array bounds [0 .. 0]
/tmp/junk.d(4): array index 0 is out of bounds [0..0]

So.. a 0 length array isn't terribly useable, which is good and a sign that it
probably shouldn't be accepted.  However, see D.bugs/6444 for some more
thoughts, specificaly as relates to empty strings.  At least with strings the
size isn't 0 due to the length byte or null terminator depending on what type
of string we're talking about, right?

So.. what is this: ice-on-valid or ice-on-invalid on the gdc side and
potentially accepts-invalid on the dmd side?


-- 




More information about the Digitalmars-d-bugs mailing list