Thread overview
[Issue 13387] Bug with arithmetic opertions on integer types smaller than int
Aug 29, 2014
Uranuz
Feb 20, 2020
Basile-z
Mar 21, 2020
Basile-z
August 29, 2014
https://issues.dlang.org/show_bug.cgi?id=13387

--- Comment #1 from Uranuz <neuranuz@gmail.com> ---
AFAIK, in C++ the same rules used, but it don't have problems with assignment of type *unsigned short = unsigned short + unsigned short*. So it's strange that we have such type of problem in D. But still integer promotions are used to, although I disagree with it.

//-------------
#include <iostream>
#include <typeinfo>

int main()
{
    unsigned short a = 5;
    unsigned short b = 3;
    unsigned short c = a + b; //This compiles

    if( typeid(a + b) == typeid(int) )
    {
        std::cout << "int" << std::endl;
    }
    else if( typeid(a + b) == typeid(unsigned short) )
    {
        std::cout << "unsigned short" << std::endl;
    }
    else if( typeid(a + b) == typeid(unsigned int) )
    {
        std::cout << "unsigned int" << std::endl;
    }

    return 0;
}
//-------------

This programme outputs:
int

--
August 29, 2014
https://issues.dlang.org/show_bug.cgi?id=13387

bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc

--- Comment #2 from bearophile_hugs@eml.cc ---
(In reply to Uranuz from comment #1)

> So it's strange that we have such type of problem in D.

It's a "problem" introduced on purposes in D.

Regarding byte+byte=int it's done like this in D to follow the C rules. I think it's hard to change this.

--
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=13387

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2

--
February 20, 2020
https://issues.dlang.org/show_bug.cgi?id=13387

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |b2.temp@gmx.com
           Hardware|x86_64                      |All
         Resolution|---                         |WONTFIX
                 OS|Linux                       |All

--- Comment #3 from Basile-z <b2.temp@gmx.com> ---
There's nothing applicable here, despite of personnal preferences. Implicit conversions and integral promotions rules are specified and this cannot change without creating massive breakages.

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=13387

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--