www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3974] New: ICE(init.c): Static array initializer with more elements than destination array

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3974

           Summary: ICE(init.c): Static array initializer with more
                    elements than destination array
           Product: D
           Version: 2.040
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au



Reported in a comment in bug 3849.

void main() {
  struct S { int x; }
  S[2] a = [{1}, {2}, {3}];
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 16 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3974


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



Regarding bug 3849, I did put both things in the same bug report because:
- they are strongly semantically related, the compiler has to refuse fixed
sized literals with a number of items different from the number specified on
the left (this is true for nD arrays too);
- The cause of this ICE can be related to the lack of tests over the number of
items in the literal compared to the number on the left. So fixing one bug can
even fix the other too, or it can be very quick to fix one when you fix the
other. That's why I have not originally marked that as enhancement.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3974


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch



Note to bearophile: The case where the number of elements is LESS than the
array size (bug 3849) is quite different. Note that, for example,
int [3] x = [ 2: 15]; is currently legal.

This patch is slightly more general, in that it covers the cases like
  int[3] toomany = [ 2: 13, 1];

PATCH: init.c line 343 (in ArrayInitializer::semantic()).


        if (length == 0)
            error(loc, "array dimension overflow");
        if (length > dim)
            dim = length;
    }

+    if (t->ty == Tsarray)
+    {
+        size_t edim = ((TypeSArray *)t)->dim->toInteger();
+        if (dim > edim)
+        {
+            error(loc, "array initializer has %d elements, but array length is
%d", dim, edim);
+            return new ExpInitializer(loc, new ErrorExp());
+        }
+    }
    unsigned long amax = 0x80000000;
    if ((unsigned long) dim * t->nextOf()->size() >= amax)
        error(loc, "array dimension %u exceeds max of %ju", dim, amax /
t->nextOf()->size());

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3974


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



Fixed DMD2.044

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 05 2010