Bug 5090 – ICE(todt.c) struct literal initializing zero length array

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-20T16:14:00Z
Last change time
2015-06-09T05:11:41Z
Keywords
accepts-invalid, ice-on-invalid-code, patch
Assigned to
bugzilla
Creator
ibuclaw

Attachments

IDFilenameSummaryContent-TypeSize
813issue5090.patchPATCH against rev 755: fix crash in first casetext/plain622
844issue5090.patchPatch for 5090text/plain1432

Comments

Comment #0 by ibuclaw — 2010-10-20T16:14:46Z
Test cases: struct A { int[0] b; } A a = A(0); // Fails, compiler aborts A b = {b:0}; // OK, but perhaps shouldn't be. A c = A([]); // OK A d = {b:[]}; // OK Although the compiler shouldn't issue an assert, a zero length array should be enforced to have a 0 length initializer. Regards
Comment #1 by bearophile_hugs — 2010-10-20T16:35:32Z
This needs to be an error, because that 0 value has nowhere to be stored into: struct A { int[0] b; } A b = {b : 0};
Comment #2 by s.d.hammett — 2010-11-15T11:33:15Z
Created attachment 813 PATCH against rev 755: fix crash in first case Fixed: A a = A(0); // Fails, compiler aborts by issuing error msg. I'll dig a bit more into fixing the second case, that should be an error as way.
Comment #3 by ibuclaw — 2010-11-15T12:11:09Z
Just under the "duplicate union" error is where to look iirc.
Comment #4 by ibuclaw — 2010-12-09T07:42:07Z
Created attachment 844 Patch for 5090 Reassigned to Walter. Attaching patch that turns assert into an error, but enforces that this corner case only happens for zero-length'd static arrays. Make any improvements you may wish to add/remove, as I generally suck at coming up with good, concise error messages. :~)
Comment #5 by ibuclaw — 2010-12-09T07:48:08Z
Just to make note, these forms of initialisation are still OK for zero-length static arrays: struct A { int[0] b; } A a = A(); // OK A b = {}; // OK A c = A([]); // OK A d = {b:[]}; // OK Regards
Comment #6 by bugzilla — 2010-12-27T15:23:49Z