[Issue 7184] parse error on *(x)++
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 4 02:36:23 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=7184
--- Comment #8 from timon.gehr at gmx.ch ---
(In reply to RazvanN from comment #1)
> Issuing an error is the correct behavior. As you can see in the grammar [1],
> *(x)++ is parsed the following way: *UnaryExpression. If a parenthesis is
> encountered, then the parser expects a type :
> (type).identifier/templateInstance.
That is the bug. The grammar allows the derivation
UnaryExpression
\
PowExpression
\
PostfixExpression
\
PostfixExpression ++
\
( PrimaryExpression )
\
...
\
Identifier
Aside: It is a bad idea to try and distinguish types from non-types in the
parser, because it just can't. I guess this grew out of the way the parser and
semantic analysis were developed. It's not a very good design.
> Since none of the above is actually encountered, the parser presumes you
> tried to do a C style cast. Note that dropping the useless parens
The parens were not useless, they just became useless because I created a
reduced test case.
> or doing
> *((x))++ works since the parser then knows that the outermost () hold a
> primary expression.
> ...
That's a workaround.
> The behavior is according to the spec,
Certainly not. The spec is also bad though. Types should be part of the
expression grammar.
> so I will close this as invalid.
It's not invalid.
>
> [1] https://dlang.org/spec/grammar.html#UnaryExpression
--
More information about the Digitalmars-d-bugs
mailing list