[Issue 1432] Bogus "overlapping initialization" error with structs, unions, and member initializers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 16 00:51:11 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=1432
--- Comment #6 from Kenji Hara <k.hara.pg at gmail.com> 2013-12-16 00:51:07 PST ---
(In reply to comment #5)
> Do we have a distinction between explicit and implicit initialization somewhere
> else in the language?
> Otherwise it's idfficult to explain, why these two differ.
> union { int a; string b = "s"; }
> union { int a = 0; string b = "s"; }
I think the main argument of this issue is, that explicitly initialized
overlapped field should be always preferred than default initializing.
The two concepts, overlapping fields and default initializing behavior for
safely programming is normally conflict each other, because Compiler cannot
initialize all of overlapped fields by default.
Therefore, D language should specially treat overlapped fields.
For union U { T1 f1; T2 f2; ... }, T1.init is picked for the default
initializer of overlapped fields.
I think it is legitimate behavior because it is C-compatible.
However, if only one overlapped fields are explicitly initialized by
programmer, current dmd behaves foolish.
union U1 { T1 f1 = x; T2 f2; }
// x is used for default initializer
union U2 { T1 f1; T2 f2 = x; }
// x conflicts with implicitly picked default initializer T1.init !
This is D-specific case, and I think the current behavior is contrary to the
two D language concepts -
1. If programmer specifies something explicitly, compiler should respect it.
2. If it is unnecessary, order dependent feature is not good.
In the U2 case, programmer explicitly add a initializer for the overlapped
field f2. So, I think compiler should pick it.
Of course, two or more overlapped fields have explicit initializers, it should
be an error.
union U3 { T1 f1 = x; T2 f2 = y;
// explicit specified initializers x and y conflicts each other
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list