[Bug 34] C style cast illegal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 15 07:39:55 PST 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=34


smjg at iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg at iname.com
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #2 from smjg at iname.com  2006-03-15 09:39 -------
(In reply to comment #1)
> (idx)+3 can be parsed as a C-style cast: (idx)(+3).

Not by any compliant D code parser.

The spec doesn't allow

    cast(int)(idx) + 3

to be parsed as anything but an AddExpression.  Indeed, I thought the whole
point of removing the old syntax was to remove the ambiguity from the grammar. 
It also specifically states

    D introduces the cast keyword:

    cast(foo) -p;    // cast (-p) to type foo
    (foo) - p;       // subtract p from foo

> These are marked as illegal
> in order to catch errors in transliterating C code into D code.

Even if the parser is fixed to match the spec, it will still throw an error
during semantic analysis if idx turns out to be a type, which is the only
situation in which it is necessary to catch the error.

An error message tailored to this special case is nice, but not necessary.  But
if you still want it....

Does the compiler still remember that idx was in brackets when it's time to do
semantic analysis?  If so, you could still do it by looking out for the form

    ( Type ) + ...

and similarly for -, ~ and *.


-- 




More information about the Digitalmars-d-bugs mailing list