On 24/09/12 17:19, Andrei Alexandrescu wrote:
On 9/24/12 4:17 AM, Don Clugston wrote:
Regarding the comma operator: I'd love to deprecate it, but even if we
don't, could we at least ensure that this kind of rubbish doesn't
compile:

void main()
{
int x;
x > 0, x += 5;
}

At present, because comma expressions are expressions, not statements,
the "x > 0" doesn't generate a "statement has no effect" error, despite
the fact that it is meaningless and gets completely discarded.

Interesting. The comma operator is probably the only one in which an
expression is evaluated only for the sake of its side effects. So
eliminating the comma operator would just get rid of that case by design.

Yes. Comma is a special case in a number of ways.

Of course, there's always the option of adding more checks or rewriting
the comma operator from "expr1, expr2, expr3" to "{ expr1; expr2; return
expr3; }()".

We hit this one often in real-world code. On German keyboards , and ; are on the same key, so it's a fairly easy typo. I don't think it happens as often when using a US keyboard.

Reply via email to