On Tue, 15 Jun 2010 09:04:23 -0400, Graham Fawcett <[email protected]>
wrote:
Hi folks,
The following statement appears in std.variant:
190 union
191 {
192 ubyte[size] store = void;
193 // conservatively mark the region as pointers
194 static if (size >= (void*).sizeof)
195 void* p[size / (void*).sizeof];
196 }
The '= void' on line 192 sometimes leads to 'Error: void initializer
has no value' errors in application code. For example, this fails to
compile on DMD 2.047:
foreach (int v; map! "a.get!int" (variantArray(1,2,3)))
writeln(v);
Changing line 192 to 'ubyte[size] store;' resolves the issue.
My question is: what is the point of the '= void' initializer here?
Would std.variant be broken if '= void' were removed?
= void means don't initialize the data. Otherwise, the compiler/runtime
will fill in the data will all 0s. However, I'm not sure how that works
with a union, since you may have conflicting requirements for
initialization.
Is there a place in the spec that covers this?
-Steve