3575 – CTFE: member structs not initialized correctly

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3575 - CTFE: member structs not initialized correctly
Summary: CTFE: member structs not initialized correctly
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2009年12月05日 01:54 UTC by Don
Modified: 2014年04月18日 09:12 UTC (History)
1 user (show)

See Also:


Attachments
Patch against DMD2.037 svn 283. (4.68 KB, patch)
2009年12月05日 01:56 UTC, Don
Details | Diff
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 Don 2009年12月05日 01:54:25 UTC
This is a couple of cases I missed in my CTFE patches in DMD2.032.
Root cause: defaultInit for a struct is a VarExp, not a StructLiteral. This needs to be applied recursively. Patch: I've added a recursive defaultInitAsStructLiteral() to TypeStruct. It needs to be called from two places in interpret.c.
---------------------------------
struct SwineFlu {
 int a; int b;
}
struct Infection {
 SwineFlu y;
}
struct IveGotSwineFlu {
 Infection x;
 int z;
 int oink() { return x.y.a+10; } 
}
int quarantine() {
 IveGotSwineFlu d;
 return d.oink();
}
struct Mexico {
 Infection x;
 int z=2;
 int oink() { return z+x.y.b; }
}
int mediafrenzy() {
 Mexico m;
 return m.oink;
}
static assert( quarantine() == 10);
static assert( mediafrenzy() == 2);
Comment 1 Don 2009年12月05日 01:56:24 UTC
Created attachment 522 [details] 
Patch against DMD2.037 svn 283.
Comment 2 Walter Bright 2009年12月30日 00:11:37 UTC
Changeset 321
Comment 3 Walter Bright 2009年12月31日 11:12:24 UTC
Fixed dmd 1.054 and 2.038


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