[Issue 19402] bitshift with long shift amount results in int instead of long

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 15 08:16:08 UTC 2019


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
The spec is simply wrong. We need to follow the C conventions here, otherwise
people will get nasty unexpected bugs. The C90 rule is:

"The integer promotions are performed on each of the operands. The type of the
result is that of the promoted left operand. If the value of the right operand
is negative or is greater than or equal to the width of the promoted left
operand, the behavior is undefined."

C++98 is pretty much the same:

"The operands shall be of integral or enumeration type and integral promotions
are performed.  The type of the result is that of the promoted left operand. 
The behavior is undefined if the right operand is negative, or greater than or
equal to the length in bits of the promoted left operand."

The D behavior is:

        exp.e1 = integralPromotions(exp.e1, sc);
        if (exp.e2.type.toBasetype().ty != Tvector)
            exp.e2 = exp.e2.castTo(sc, Type.tshiftcnt);

which matches the C/C++ behavior. The compiler is right, the spec is wrong.

--


More information about the Digitalmars-d-bugs mailing list