858 – Forward reference to struct inside class crashes the compiler

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 858 - Forward reference to struct inside class crashes the compiler
Summary: Forward reference to struct inside class crashes the compiler
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: Walter Bright
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 340
Show dependency tree / graph
Reported: 2007年01月19日 14:35 UTC by georg.ramme
Modified: 2014年02月15日 13:12 UTC (History)
1 user (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 georg.ramme 2007年01月19日 14:35:59 UTC
E:\prog\>dmd dontwork.d
---
The instruction as "0x004565b9" referenced memory at "0x00000038". The memory could not be "read".
---
E:\prog\>dmd work.d
E:\apps\dm\bin\link.exe work,,,user32+kernel32/noi;
/** dontwork.d **/
class Outer
{
 public:
 this()
 {
 B sc = new B();
 }
 class B
 {
 Strct str;
 }
}
struct Strct
{
 int i;
}
int main(char[][] args)
{
 return 0;
}
/** work.d **/
struct Strct
{
 int i;
}
class Outer
{
 public:
 this()
 {
 B sc = new B();
 }
 class B
 {
 Strct str;
 }
}
int main(char[][] args)
{
 return 0;
}
***
Comment 2 Christian Kamm 2008年11月04日 05:04:10 UTC
The code generation seems to crash because the vthis member of Inner's ClassDeclaration is NULL. 
This happens when semantic is called again from runDeferredSemantic: first vthis is set to baseClass->vthis (baseClass is Object and vthis there is NULL) and then the interface and nested code isn't run again to correct it because sizeok != 0.
Comment 3 Christian Kamm 2008年11月04日 05:10:49 UTC
I looked at the code in dstress, not the one posted here. The Inner in my description is georg's inner B class.
Comment 4 Don 2009年05月14日 05:04:02 UTC
No longer segfaults in DMD2.040 and 1.030. Still doesn't compile (generates a forward reference error).
However, the original bug is fixed.
TEST CASE:
---
class A{
 class B {
 S s;
 }
 void foo() {
 B b = new B();
 }
}
struct S {}
---
ice.d(6): Error: forward reference to B


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