if(arr) now a warning

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 9 21:25:55 PDT 2015


On Fri, Apr 10, 2015 at 01:01:48PM +1000, Daniel Murphy via Digitalmars-d wrote:
> "H. S. Teoh via Digitalmars-d"  wrote in message
> news:mailman.1388.1428620346.3111.digitalmars-d at puremagic.com...
> 
> >It's akin to a similar change sometime ago that made bare pointers in
> >if-conditions illegal: writing `if (ptr && ...)` will cause the
> >compiler to complain loudly. When this first got in, one of my
> >projects broke, and I was rather annoyed at the time. However, when I
> >got around to fixing it, I found that I had to write `if (ptr !is
> >null && ...)` instead, which greatly clarifies the intent and
> >readability of the code.  Since then, I have come to appreciate this
> >change.
> 
> Except that never happened.  Maybe you're thinking of comparing
> objects to null with ==?

Are you sure?

My original failing code was:

	while (!lex.empty &&
		(op = T.matchOp(lex.front, OpType.infix)) &&
		op.precedence >= minprec)
	{
		...
	}

where op is a pointer type.


T

-- 
In a world without fences, who needs Windows and Gates? -- Christian Surchi


More information about the Digitalmars-d mailing list