[Issue 18534] New: Wrong code for ?: operator when compiling with -O

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 27 19:53:28 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18534

          Issue ID: 18534
           Summary: Wrong code for ?: operator when compiling with -O
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: hsteoh at quickfur.ath.cx

Code:
-------
auto foo(int invert)
{
    import std.format : format;
    return format("%c", invert ? 'A' : 'A');
}
void main()
{
    auto s = foo(0);
    assert(s == "A"); // assertion fails
}
-------

Compile command:
-------
dmd -O -run test.d
-------

Inspecting the contents of s reveals that instead of containing the character
'A', it contains 0xFF instead.

Compiling without -O fixes the problem.  Replacing the conditional with just
'A' also makes the problem go away.  Seems like -O generates wrong code for the
?: operator.

--


More information about the Digitalmars-d-bugs mailing list