Bug 869 – Cast of a parenthesized expression combined with !is is mistaken for a C style cast and a template specialization
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-01-21T08:42:00Z
Last change time
2014-02-15T13:13:19Z
Keywords
patch, rejects-valid, spec
Assigned to
nobody
Creator
matti.niemenmaa+dbugzilla
Comments
Comment #0 by matti.niemenmaa+dbugzilla — 2007-01-21T08:42:04Z
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.
Comment #1 by thomas-dloop — 2007-01-23T07:46:18Z
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
#
Comment #2 by kamm-removethis — 2009-06-30T10:33:34Z
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 !=.
Comment #3 by clugdbug — 2009-12-15T14:22:17Z
This was fixed between 1.030 and 1.036.
No spec change is required (precedence is implied in the BNF descriptions).