[Issue 10995] CTFE failures for structs with void initialized members

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 13 03:44:13 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10995



--- Comment #7 from monarchdodra at gmail.com 2013-09-13 03:44:12 PDT ---
(In reply to comment #6)
> (In reply to comment #5)
> > I think this point (issuing not initialized error) is wrong. Regardless of what
> > dmd does produce in runtime (technically speaking dmd didn't ignored void
> > initializer for fields - its presence actually affected behavior),
> 
> That's only because it's been generating extremely bad code.
> Intuitively, initializing a struct should be the same as initializing each
> member individually.
> 
> struct S { 
>    int a = 2;
>    int b = void;
> }
> 
> S s;
> 
> should mean:
> S s = void;
> S.a = S.a.init;
> S.b = S.b.init;
> and only the S.a case should generate any code.

Just for the record, you should never initialize a struct instance like this.
If you do this, then the padding bytes will not be initialized. This is
important, as if S has no elaborate opEquals, comparison becomes a straight up
memcompare, which will unconditonally scan the totality of S, padding and all.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list