[Issue 9904] typeof(null) can be casted to aggregate type if .sizeof	equals size of pointer
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Apr  8 10:31:57 PDT 2013
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=9904
--- Comment #3 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-04-08 10:31:56 PDT ---
(In reply to comment #2)
> (In reply to comment #1)
> 
> > Those should really use size_t to reproduce on all systems:
> > 
> > > struct S1
> > > {
> > >     size_t x;
> > > }
> > > 
> > > struct S2
> > > {
> > >     size_t x;
> > >     byte b;
> > > }
> 
> Why is that cast a problem/bug? Maybe there is no compiler bug here.
It may not do what the user expects. For example they might think this is a
good way to initialize the struct to its default value, but it's wrong:
import std.math;
struct S
{
    float x;
}
void main()
{
    auto s1 = S.init;
    auto s2 = cast(S)null;
    assert(isnan(s1.x));
    assert(isnan(s2.x));  // fails
}
-- 
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