Thread overview | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 16, 2011 [Issue 6681] New: bogus duplicate union initialization or overlapping initialization errors | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=6681 Summary: bogus duplicate union initialization or overlapping initialization errors Product: D Version: D1 & D2 Platform: Other OS/Version: Mac OS X Status: NEW Severity: regression Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: fawzi@gmx.ch --- Comment #0 from Fawzi Mohamed <fawzi@gmx.ch> 2011-09-16 10:42:44 PDT --- In D1 code like this {{{ module t; template MTuple( TList... ) { alias TList MTuple; } struct V{ union { double[2] cell; version(v2) {} else { MTuple!(double,double) tuple; } struct { union { double x; double r; } union { double y; double g; } } } static const V zero={x:0, y:1}; } V a=V.zero; version(v2) { struct Q { union { struct { double x, y; } V xyzw; } const static Q id = { x: 0, y:1 }; } Q b=Q.id; } }}} fails with duplicate union initialization, which is incorrect. This happens both with and without -version=v2 which shows that the error is not just the tuple. Closely related errors are present also in D2, even if one uses constructors: {{{ module t; template MTuple( TList... ) { alias TList MTuple; } struct V{ this(double a,double b){ x=a; y=b; } union { double[2] cell; version(v2) {} else { MTuple!(double,double) tuple; } struct { union { double x; double r; } union { double y; double g; } } } static immutable V zero=V(0,1); } V a=V.zero; version(v2) { struct Q { union { struct { double x, y; } V xyzw; } immutable static Q id =Q(0,1); } Q b=Q.id; } }}} similar errors seem to be very old: http://www.digitalmars.com/d/archives/digitalmars/D/bugs/6271.html and there are related or very similar errors are already present in bugzilla: http://d.puremagic.com/issues/show_bug.cgi?id=4241 which basically uses the same code as me (omg derived vector structs), but just complains about line number, seemingly accepting the error (which is bogus imho. I have also tried to sprinkle around some =void but I just managed to end up with "Error: no initializer for union". http://d.puremagic.com/issues/show_bug.cgi?id=1432 (using initializers in the union) but this one at least with D1 is a regression from 1.067 at least -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 25, 2011 [Issue 6681] bogus duplicate union initialization or overlapping initialization errors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla@digitalmars.com --- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2011-10-24 20:57:25 PDT --- There have been several patches to 'fix' struct/union initialization. Evidently, we need to step back a bit and rethink/reengineer it. Something along the lines of: 1. Create a list of all the fields, in lexical order. Each field will have a beginning offset and an ending offset. One field 'overlaps' another if its offset range overlaps the other. 2. Examine list of initializers. Unnamed initializers will be associated with a field as follows: 1. if it's the first initializer, it's the first field. Done. 2. start with the previous field that was initialized. Move forward through the field list and pick the first field that does not overlap with that previous field. That will be the field associated with that initializer. 3. If any initialized field overlaps with any other initialized field, error. 4. Go back through the field list again, in order. If a field does not have an initializer, and does not overlap with any other initialized field, assign it the default initializer. At this point, I wish to defer this to the next update. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 01, 2012 [Issue 6681] bogus duplicate union initialization or overlapping initialization errors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies@gmail.com --- Comment #2 from yebblies <yebblies@gmail.com> 2012-02-01 22:58:33 EST --- Ok, the first test case reduces to this: struct V{ union { double[2] cell; double x; } static immutable V zero=V(0,1); } The problem being that the struct literal gets turned into: this(a, b) { cell = 0; x = 1; } ie. it passes the first argument to the first member, and the second argument to the second. This is sort of what I'd expect to happen, but the error message is completely valid for what it's trying to do. If anyone has a better idea of how struct literals should map to unions, please open another bug report about it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 01, 2012 [Issue 6681] struct constructor call is converted to struct literal that breaks union initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Platform|Other |All Summary|bogus duplicate union |struct constructor call is |initialization or |converted to struct literal |overlapping initialization |that breaks union |errors |initialization OS/Version|Mac OS X |All --- Comment #3 from yebblies <yebblies@gmail.com> 2012-02-01 23:10:11 EST --- Got my test cases a little mixed up there, but it's still mostly valid. All of the non-struct-literal struct construction seems to be converted into struct literals. eg. struct S { this(int a, int b) { this.a = b; this.b = a; } union { ulong g; struct {int a, b; }; } } static immutable S s = S(0, 1); Prints: (with a little extra debug output) StructLiteralExp::semantic('S(0LU,1,0)') S Error: duplicate union initialization for a Error: duplicate union initialization for b As you can see, it make a struct literal with every field accounted for. So this is a bug in the constfolding/ctfe code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 01, 2012 [Issue 6681] struct constructor call is converted to struct literal that breaks union initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug@yahoo.com.au --- Comment #4 from Don <clugdbug@yahoo.com.au> 2012-02-01 04:18:34 PST --- (In reply to comment #3) > > As you can see, it make a struct literal with every field accounted for. > > So this is a bug in the constfolding/ctfe code. Not exactly. It's a compiler structural problem: there's no way to specify a struct literal with missing fields. Struct static initializers can do it, but struct literals cannot. I think the solution is to merge struct literals with struct static initializers, as it says in a TODO in the code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 01, 2012 [Issue 6681] struct constructor call is converted to struct literal that breaks union initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 --- Comment #5 from yebblies <yebblies@gmail.com> 2012-02-02 00:02:06 EST --- (In reply to comment #4) > Not exactly. It's a compiler structural problem: there's no way to specify a struct literal with missing fields. Struct static initializers can do it, but struct literals cannot. > > I think the solution is to merge struct literals with struct static initializers, as it says in a TODO in the code. One of the D1 cases seems to have the same problem with struct static initializers. Can't this be done by just nulling out the untouched fields in the Expressions array and ensuring at least one field gets initialized? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 01, 2012 [Issue 6681] struct constructor call is converted to struct literal that breaks union initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 --- Comment #6 from Don <clugdbug@yahoo.com.au> 2012-02-01 07:13:36 PST --- (In reply to comment #5) > (In reply to comment #4) > > Not exactly. It's a compiler structural problem: there's no way to specify a struct literal with missing fields. Struct static initializers can do it, but struct literals cannot. > > > > I think the solution is to merge struct literals with struct static initializers, as it says in a TODO in the code. > > One of the D1 cases seems to have the same problem with struct static initializers. Can't this be done by just nulling out the untouched fields in the Expressions array and ensuring at least one field gets initialized? Maybe. The order of fields in a struct is fixed, so in theory that ought to work. It's a while since I last looked at it, but I remember there were severe problems with anonymous unions nested inside anonymous unions. There's code elsewhere in the compiler which tries to identify fields based on their type + offset, but that cannot work. It appears to work at the moment, but only because it assumes when fields are initialized in order with no gaps. Still, I've fixed some of those compiler bugs recently, so maybe it's more possible now. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 01, 2012 [Issue 6681] struct constructor call is converted to struct literal that breaks union initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 --- Comment #7 from yebblies <yebblies@gmail.com> 2012-02-02 03:38:36 EST --- Ok, I'll take a look at it tomorrow unless you want it. I know there are at least two places it checks for overlapping union initialization, one in expression.c and one somewhere in the glue, maybe e2ir? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 02, 2012 [Issue 6681] struct constructor call is converted to struct literal that breaks union initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 --- Comment #8 from Don <clugdbug@yahoo.com.au> 2012-02-02 03:26:11 PST --- (In reply to comment #7) > Ok, I'll take a look at it tomorrow unless you want it. I know there are at least two places it checks for overlapping union initialization, one in expression.c and one somewhere in the glue, maybe e2ir? The big one is in init.c. Around line 340 there's code I wrote (to replace the code in 320..340). Walter disabled that code a bit later, but he didn't say why. Would be great if you could take a fresh look at it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 17, 2012 [Issue 6681] struct constructor call is converted to struct literal that breaks union initialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | http://d.puremagic.com/issues/show_bug.cgi?id=6681 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |rejects-valid AssignedTo|nobody@puremagic.com |yebblies@gmail.com --- Comment #9 from yebblies <yebblies@gmail.com> 2012-02-17 21:07:11 EST --- I think for this to work, the interpreter needs to be able to handle uninitialized values, and unions need to default to void initializers. I have a patch for this that is nearly ready, and solves issue 6438 at the same time. -- 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