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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5090 - ICE(todt.c) struct literal initializing zero length array
Summary: ICE(todt.c) struct literal initializing zero length array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Walter Bright
URL:
Keywords: accepts-invalid, ice-on-invalid-code, patch
Depends on:
Blocks:
Reported: 2010年10月20日 16:14 UTC by Iain Buclaw
Modified: 2015年06月09日 05:11 UTC (History)
3 users (show)

See Also:


Attachments
PATCH against rev 755: fix crash in first case (622 bytes, patch)
2010年11月15日 11:33 UTC, simon
Details | Diff
Patch for 5090 (1.40 KB, patch)
2010年12月09日 07:42 UTC, Iain Buclaw
Details | Diff
Show Obsolete (1) Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2010年10月20日 16:14:46 UTC
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 bearophile_hugs 2010年10月20日 16:35:32 UTC
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 simon 2010年11月15日 11:33:15 UTC
Created attachment 813 [details] 
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 Iain Buclaw 2010年11月15日 12:11:09 UTC
Just under the "duplicate union" error is where to look iirc.
Comment 4 Iain Buclaw 2010年12月09日 07:42:07 UTC
Created attachment 844 [details] 
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 Iain Buclaw 2010年12月09日 07:48:08 UTC
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 Walter Bright 2010年12月27日 15:23:49 UTC
http://www.dsource.org/projects/dmd/changeset/823 


AltStyle によって変換されたページ (->オリジナル) /