[Issue 7184] parse error on *(x)++

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 3 14:47:45 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=7184

--- Comment #6 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
You're at least partly right, though (a[b]).c does work. The smallest example
of this bug is probably this:

unittest {
    (a)++;
}

That should of course fail to compile as well, but for other reasons. This
should compile:

unittest {
    int a;
    (a)++;
}

Are there any cases where this is valid with 'a' being a type? No. The compiler
even complains about exactly that: "C style cast illegal, use cast(a)++0".
++(T), where T has overloaded static opUnary, should and does work, but the
postfix version does not, because the lowering doesn't make sense.

Another example of where this bug shows up is with call expressions:

void foo(int n) {}
unittest {
    (foo)(3);
}

(parameter added because the compiler gives up and spews other errors when
getting empty parentheses)

For comparison, (a)++ compiles and runs with expected semantics in C#, C++ and
Javascript.

It seems to me that this is in fact not a spec error, but that the parser is
misbehaving when reporting this error. It gives up when it sees that the next
character after (a) is not a period[0], while the grammar seems to support a
test for PowExpression, to find that (a) is a PrimaryExpression on the form
(Expression), and continue down that route. The error message is printed long
before the parser knows that the stuff inside the parentheses is a type.

[0]:
https://github.com/dlang/dmd/blob/1fa67d062b8d755b11722ea112af63cb34cc06b7/src/ddmd/parse.d#L7959

--


More information about the Digitalmars-d-bugs mailing list