[Issue 3789] [TDPL] Structs members that require non-bitwise comparison not correctly compared

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 24 13:26:46 PDT 2013


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


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #28 from monarchdodra at gmail.com 2013-04-24 13:26:39 PDT ---
(In reply to comment #27)
> (In reply to comment #26)
> > (In reply to comment #22)
> > > Just want to note the compiler often can't optimize a comparison to be bitwise
> > > because of align gaps which also should be ignored to conform `opEquals`
> > > behavior.
> > 
> > The holes must be initialized to zero, by definition, so that a bitwise
> > comparison can be done.
> 
> Nop. Holes are holes, that's all.

Technically, D initializes all variables by first blitting T.init over them,
which contains implementation defined values for the holes.

"Thanks" to this, the implementation may make optimizations that makes
assumptions on the values in the gaps.

So even if you've initialized all the variables in a struct, if don't first
blit the struct itself, your struct will be in a globally "not fully
initialized" state. From there, an opEqual may fails, which would be legitimate
undefined behavior.

So even if "holes are holes", D's intialization mechanics mean they have
defined values.

-- 
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