digitalmars.D.bugs - [Issue 18770] New: Ternary operator returns incorrect value when
- d-bugmail puremagic.com (41/41) Apr 17 2018 https://issues.dlang.org/show_bug.cgi?id=18770
https://issues.dlang.org/show_bug.cgi?id=18770 Issue ID: 18770 Summary: Ternary operator returns incorrect value when compiling with -O option Product: D Version: D2 Hardware: x86 OS: Mac OS X Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: nebukuro09 gmail.com Code: import std.stdio; void main() { foreach (i; 0..2) { long x = (i % 2 == 0) ? 1 : -1; x.writeln; } } ----- Output (with -O option): 1 4294967295 ----- Output (without -O option): 1 -1 ----- It seems that -1 is implicitly converted to uint. As far as I tried, this behavior does not occur when... int x = (i % 2 == 0) ? 1 : -1 long x = (i % 2 == 0) ? -2 : -1 long x = false ? 1 : -1 All of the above correctly returns negative value with -O option. --
Apr 17 2018