Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 25, 2009 [Issue 3551] New: nested struct => dmd adds a hidden pointer | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3551 Summary: nested struct => dmd adds a hidden pointer Product: D Version: 2.036 Platform: Other OS/Version: All Status: NEW Keywords: wrong-code Severity: regression Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: nfxjfg@gmail.com --- Comment #0 from nfxjfg@gmail.com 2009-11-25 02:16:13 PST --- Take this code: void main() { struct X { int x; int bar() { return x; } } X s; } dmd2 adds a hidden pointer to struct X. That means s.sizeof==8. For extra buggyness, the hidden pointer appears in s.tupleof. This silently breaks many uses of structs. Especially it breaks C compatibility, the bit-layout for asm code, and whatever you think of. At the very least, dmd should never add a hidden pointer if that hidden pointer gets is not needed. Actually, I consider this an anti-feature, because dmd should NEVER add (non-static) hidden fields to structs. The request to fix or remove this feature is part of this bug report. The language spec should also be fixed. Note that even if the hidden pointer is added only if needed, this is still bug-prone, because it requires complicated semantic analysis just to tell, whether the struct's size got messed up. I propose to add a "dynamic" attribute for nested structs. If a struct is tagged with "dynamic", it can reference variables from its enclosing scope, and may need a hidden pointer. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 25, 2009 [Issue 3551] nested struct => dmd adds a hidden pointer | ||||
---|---|---|---|---|
| ||||
Posted in reply to nfxjfg@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=3551 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug@yahoo.com.au --- Comment #1 from Don <clugdbug@yahoo.com.au> 2009-11-25 02:21:53 PST --- (In reply to comment #0) > Take this code: > > void main() { > struct X { > int x; > int bar() { return x; } > } > X s; > } > > dmd2 adds a hidden pointer to struct X. That means s.sizeof==8. For extra buggyness, the hidden pointer appears in s.tupleof. > > This silently breaks many uses of structs. Especially it breaks C compatibility, the bit-layout for asm code, and whatever you think of. > > At the very least, dmd should never add a hidden pointer if that hidden pointer gets is not needed. > > Actually, I consider this an anti-feature, because dmd should NEVER add (non-static) hidden fields to structs. The request to fix or remove this feature is part of this bug report. The language spec should also be fixed. Note that even if the hidden pointer is added only if needed, this is still bug-prone, because it requires complicated semantic analysis just to tell, whether the struct's size got messed up. > > I propose to add a "dynamic" attribute for nested structs. If a struct is tagged with "dynamic", it can reference variables from its enclosing scope, and may need a hidden pointer. In the spec, that's what static structs are for. Nested _anything_ has this behaviour. Declare it as a static struct if you don't want the hidden pointer. Please close this bug as invalid, and create a new one: "static nested structs are not implemented". -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 30, 2009 [Issue 3551] nested struct => dmd adds a hidden pointer | ||||
---|---|---|---|---|
| ||||
Posted in reply to nfxjfg@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=3551 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla@digitalmars.com --- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2009-11-30 02:22:08 PST --- Declaring the struct as static should work, I'll make that fix. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 06, 2009 [Issue 3551] nested struct => dmd adds a hidden pointer | ||||
---|---|---|---|---|
| ||||
Posted in reply to nfxjfg@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=3551 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED --- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2009-12-06 00:55:04 PST --- Fixed dmd 2.037 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation