In what situation can new Struct() return null?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri May 10 17:54:44 UTC 2019


On Fri, May 10, 2019 at 05:32:25PM +0000, faissaloo via Digitalmars-d-learn wrote:
> On Friday, 10 May 2019 at 12:19:29 UTC, Cym13 wrote:
> > On Friday, 10 May 2019 at 10:11:51 UTC, faissaloo wrote:
> > > My program contains the following statement:
> > >     auto newChildNode = new Node();
> > > 
> > > In debugging I have found that this pointer evaluates to null,
> > > what could cause this? I should have plenty of memory, my only
> > > other idea is some sort of heap corruption.
> > 
> > Could you share a complete, concise, compilable example
> > demonstrating that bug? One line is rather short to understand
> > what's happening.
> 
> Unfortunately not, I can't seem to reproduce it outside my codebase.

Perhaps try Dustmite on it?

AFAIK, calling new on a struct should never return null. So there must
be something else not quite right here.  But without actual code it's
anybody's guess as to what it might be.

The last time I heard somebody run into this, it was caused by some
unrelated compiler codegen bug that left the CPU registers in an
inconsistent state, thus causing an unrelated call to `new` to return
the wrong value.  Perhaps you could try a different compiler to see if
that makes a difference?


T

-- 
The fact that anyone still uses AOL shows that even the presence of options doesn't stop some people from picking the pessimal one. - Mike Ellis


More information about the Digitalmars-d-learn mailing list