static assert (cast(int)(foo) !is null); // or with normal assert: void main() { assert (cast(int)(foo) !is null); } The above code snippet produces, for both lines 1 and 3, the following pair of errors: (type identifier : specialization) expected following is C style cast illegal, use cast(foo)!0 It's easy to work around: either remove the parentheses around foo or add another pair of them, whichever is appropriate for the expression.
http://www.digitalmars.com/d/overview.html >D retains C operators and their precedence rules, order of evaluation rules, and promotion rules. As C hasn't got an "!is" operator it is impossible to decide how this code should be interpreted: # # cast(int)(foo !is null) // 1 # (cast(int)foo) !is null // 2 #
DMD 1.045 digests the following test case without complaint: class C {} C foo; void main() { assert (cast(Object)(foo) !is null); } To resolve this issue, add the following line to "Identity Expressions": The is and !is expressions have the same precedence as the equality expressions == and !=.
This was fixed between 1.030 and 1.036. No spec change is required (precedence is implied in the BNF descriptions).