Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 01, 2010 [Issue 4967] New: { } struct literals not documented, and not working | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4967 Summary: { } struct literals not documented, and not working Product: D Version: D2 Platform: x86 OS/Version: Windows Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: ah08010-d@yahoo.com --- Comment #0 from Austin Hastings <ah08010-d@yahoo.com> 2010-10-01 06:24:48 PDT --- I unthinkingly created a struct literal like S s = { 9 }; and it worked (which, now that I'm complaining about it, I can't find documented in the chm). But this format doesn't appear to initialize any other fields: $ cat test.d import std.stdio; struct S { int key; int x = 1; void dump() { writefln("%s %s", key, x); } } void main() { S s1; s1.dump; S s2 = { 9 }; s2.dump; } This code prints: $ dmd -run test.d 0 1 9 1310436 Note the trash in the second variable. I am not sure what the correct solution is - should struct literals require ctor style, or use static-initializer format and an implicit copy? - but I would certainly have appreciated a warning, if nothing else, when I started compiling code like this. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 01, 2010 [Issue 4967] { } struct literals not documented, and not working | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 nfxjfg@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nfxjfg@gmail.com Version|D2 |D1 --- Comment #1 from nfxjfg@gmail.com 2010-10-01 06:45:29 PDT --- They're deprecated in D2. I think D1 has them documented. Maybe should mark this as INVALID. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 01, 2010 [Issue 4967] { } struct literals not documented, and not working | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 --- Comment #2 from Austin Hastings <ah08010-d@yahoo.com> 2010-10-01 07:31:35 PDT --- If they're deprecated in D2 but present in D1, why is this now a D1 ticket? The problem (for me) is with D2. If they're deprecated, etc., then all the more reason for dmd2 to issue a warning. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 01, 2010 [Issue 4967] { } struct literals not documented, and not working | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug@yahoo.com.au Version|D1 |D1 & D2 --- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-10-01 07:37:57 PDT --- (In reply to comment #1) > They're deprecated in D2. I hope that will happen, but so far it hasn't. They are still in the spec. > I think D1 has them documented. > Maybe should mark this as INVALID. They are documented in D2, in struct.html. It says: "The static initializer syntax can also be used to initialize non-static variables, provided that the member names are not given. The initializer need not be evaluatable at compile time." But in DMD, ever since CTFE was introduced, it must be evaluatable at compile time. The implementation is also full of bugs. For example, see bug 3271. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 29, 2012 [Issue 4967] member default initializers not working in static struct initializers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|{ } struct literals not |member default initializers |documented, and not working |not working in static | |struct initializers --- Comment #4 from Don <clugdbug@yahoo.com.au> 2012-05-29 00:56:54 PDT --- They are documented in struct.html, "Static Initialization of Structs" The bug is that default initializers are ignored for members which aren't in the struct static initializer. When this bug was originally filed, they got garbage. Now they use the default initializer for the type, but they should use the member initializer, if one is present. Barely tested patch, in init.c (350), StructInitializer::toExpression(): if (!(*elements)[i]) // Default initialize + if (vd->init) + (*elements)[i] = vd->init->toExpression(); + else (*elements)[i] = vd->type->defaultInit(); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 29, 2012 [Issue 4967] member default initializers not working in static struct initializers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dsimcha@yahoo.com --- Comment #5 from Don <clugdbug@yahoo.com.au> 2012-05-29 00:59:48 PDT --- *** Issue 6396 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 29, 2012 [Issue 4967] member default initializers not working in static struct initializers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mrmocool@gmx.de --- Comment #6 from Don <clugdbug@yahoo.com.au> 2012-05-29 01:02:58 PDT --- *** Issue 7058 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 29, 2012 [Issue 4967] member default initializers not working in static struct initializers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #7 from Don <clugdbug@yahoo.com.au> 2012-05-29 05:59:51 PDT --- https://github.com/D-Programming-Language/dmd/pull/968 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 31, 2012 [Issue 4967] member default initializers not working in static struct initializers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 --- Comment #8 from github-bugzilla@puremagic.com 2012-05-30 23:18:49 PDT --- Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a13f8d15b1f91ddece6e49c627925a386674ed7c Fix issue 4967 member default initializers not working in static struct initializers If a member has an initializer, use it in prefence to the initializer for the type. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 31, 2012 [Issue 4967] member default initializers not working in static struct initializers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Austin Hastings | http://d.puremagic.com/issues/show_bug.cgi?id=4967 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Resolution| |FIXED -- 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