3426 – ICE(optimize.c): struct literal with cast, as function default parameter.

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3426 - ICE(optimize.c): struct literal with cast, as function default parameter.
Summary: ICE(optimize.c): struct literal with cast, as function default parameter.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
Reported: 2009年10月20日 12:17 UTC by Don
Modified: 2014年02月16日 15:21 UTC (History)
2 users (show)

See Also:


Attachments
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年10月20日 12:17:43 UTC
An ancient bug: same ICE on D1.020 as on D2.036
TEST CASE:
struct Ashes {
 int ashes = cast(int)0;
}
void funky (Ashes s = Ashes()) {}
void funk() {
 funky();
}
PATCH: This patch also fixes the closely related bug 3422.
 (The semantic is for this bug. The implicit cast is for bug 3422.
The assert is just a precaution).
expression.c line 3271.
	 {	e = v->type->defaultInit();
		e->loc = loc;
	 }
	 offset = v->offset + v->type->size();
	}
+ assert(v->type);	
+	e= e->semantic(sc);
+	if (e->type !=v->type) e = e->implicitCastTo(sc, v->type);
	elements->push(e);
 }
Comment 1 Walter Bright 2009年10月31日 18:14:32 UTC
The fix for this is somewhat more complicated than the patch. The problem is the scope of the field initializer is the scope of where the field appears, not where the field is used. I'll see if I can fix it.
Comment 2 Kosmonaut 2009年10月31日 21:31:22 UTC
Fixed in SVN repository: http://www.dsource.org/projects/dmd/changeset/230 
Comment 3 Walter Bright 2009年11月06日 11:31:45 UTC
Fixed dmd 1.051 and 2.036


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