Warn about do nothing expressions?

monarch_dodra monarchdodra at gmail.com
Mon Mar 31 09:07:25 PDT 2014


On Monday, 31 March 2014 at 15:51:03 UTC, Justin Whear wrote:
> Trying to insult me isn't going to make you right, nor will an 
> appeal to
> unicorns.  With a well-defined order-of-operations, this might 
> be correct
> behavior;

Actually, regardless of order of operation, specs says you still 
get "i" un-incremented, since opEquals's lhs has no side effects 
anyways.

...The only way to have some other result, is if there was some 
sort of undefined behavior in the statement, at which point there 
is no more concept of "correct behavior"

> in this case I suspect D is like C and that this is undefined
> behavior

Yup. It's undefined behavior. I replied too fast and missed it.

> thus I would support making this statement illegal or at least
> warning.

The issue is that the legality of this can't be checked at the 
semantic phase.

It depends on *who* the left and right hand sides are. It's 
obvious in "i = i++;", but if you start mixing function calls, 
references and whatnot, the line becomes more blurry:

//----
int i;
auto p = &i;
*p = i++; //Legal? Illegal?
//----

So this means making it illegal is out of the question.

As for making it a warning, well, Walter is (AFAIK) pretty much 
against having any warnings at all, short of straight up 
deterministic semantic warnings "dangling else"/"deprecation".


More information about the Digitalmars-d mailing list