[Issue 17637] New: Integral promotion rules not being followed

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 11 14:43:27 PDT 2017


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

          Issue ID: 17637
           Summary: Integral promotion rules not being followed
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

Johan Engelen reports:


  import core.stdc.stdio;

  void main() {
    uint total = 0;
    void add(int x) { total += x; }
    ubyte popCount() { return 5; }

    add(popCount());
    add(-popCount());
    printf("%u\n", total);    // different result from C
  }

The trouble is that -popCount() negates the ubyte before promoting to int,
instead of after.

--


More information about the Digitalmars-d-bugs mailing list