Warn about do nothing expressions?

Justin Whear justin at economicmodeling.com
Fri Mar 28 13:59:34 PDT 2014


On Fri, 28 Mar 2014 19:35:20 +0000, Frustrated wrote:

> 
> either way, all increment i, which actually never happens in D. As was
> pointed out, VS does it properly... D does it wrong. Accept it and stop
> trying to validate how D does it so you can say D is correct.
> 
> Not only is it logically wrong, it is not consistent with previous
> interpretations of other compilers/languages nor with itself. It is
> wrong on all levels. Just because you believe in unicorns doesn't prove
> that they exist. All the evidence says you are wrong.
> 

Nope, Frustrated is the one who is dead wrong.

test.c:
-----------------------------
#include <stdio.h>

int main()
{
	int i = 0;
	i = i++;
	printf("%i\n", i);
	return 0;
}
-----------------------------

$ gcc test.c && ./a.out
0

$ clang test.c && ./a.out
test.c:7:7: warning: multiple unsequenced modifications to 'i' [-
Wunsequenced]
        i = i++;
          ~  ^
1 warning generated.
0


Both gcc and clang agree that in C, assigning a post-increment to itself 
results in the original value.  At least Clang warns, which is good, but 
D is consistent with C's behavior on this point.

Justin


More information about the Digitalmars-d mailing list