Conditional ? bug
Tydr Schnubbis
fake at address.dude
Fri Oct 6 04:51:21 PDT 2006
Max Samuha wrote:
> class Test
> {
> int foo()
> {
> return 1;
> }
> }
>
> void main()
> {
> Test test = null;
> int i = test != null ? test.foo() : 0;
> }
>
> This throws access violation exception
From http://www.digitalmars.com/d/expression.html#EqualExpression :
"For class and struct objects, the expression (a == b) is rewritten as
a.opEquals(b), and (a != b) is rewritten as !a.opEquals(b)."
So you have to use "test != null ? test.foo() : 0" for that kind of
thing. Just "test ? test.foo() : 0" works too.
More information about the Digitalmars-d-bugs
mailing list