Bug 17406 – int var = 10; write(--var,' ',var^^2); //output: 9 100 //NOT: 9 81

Status
RESOLVED
Resolution
DUPLICATE
Severity
trivial
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2017-05-18T09:42:00Z
Last change time
2017-05-18T15:16:41Z
Assigned to
nobody
Creator
fordlangcomments

Comments

Comment #0 by fordlangcomments — 2017-05-18T09:42:18Z
import std.stdio; void main() { int num = 10, whatisit; /* in the following code, ^^ does not work as intended, num^^2 is displayed as num not decremented or incremented: */ write(--num,' ',num*num,' ',num^^2,'\n'); //ouput: 9 81 100 //NOT: 9 81 81 write(++num,' ',num*num,' ',num^^2); //ouput: 10 100 81 //NOT: 10 100 100 /* as long as num is not incremented or decremented in write() or writeln() ^^ works as intended: */ write('\n',num*num,' ',num^^2); //output: 100 100 /* when num is incremented or decremented and num^^2 is assigned, ^^ works as intended: */ write('\n',--num,' ',num*num,' ',whatisit = num^^2); //ouput: 9 81 81 write("\n",++num,' ',num*num,' ',num^^=2,'\n'); //output: 10 100 100 }//DMD64 D Compiler v2.074.0
Comment #1 by ag0aep6g — 2017-05-18T15:16:41Z
Works correctly with dmd from git master. Prints "9 81 81" and "10 100 100". The problem has been fixed in the PR that fixed issue 16408 [1]. So I'm closing this as a duplicate. Feel free to undo if you think something more needs to be done here. [1] https://github.com/dlang/dmd/pull/6705 *** This issue has been marked as a duplicate of issue 16408 ***