Bug or Feature: unsigned integer overflow

Tobias Pankrath tobias at pankrath.net
Sat Dec 14 09:33:13 UTC 2019


On Saturday, 14 December 2019 at 07:44:37 UTC, berni44 wrote:
> On Saturday, 14 December 2019 at 07:09:30 UTC, Tobias Pankrath 
> wrote:
>> void main()
>> {
>>     auto x = 9223372036854775808; // long.max + 1
>> }
>
> You need to tell, that this is an unsigned long literal, else 
> the compiler treats it as an int:
>
> void main()
> {
>     auto x = 9223372036854775808UL; // long.max + 1
> }

As far as I understand the spec, the type is inferred from the 
value range:

> Literal Type
> Usual decimal notation
>0 .. 2_147_483_647 int
> 2_147_483_648 .. 9_223_372_036_854_775_807 long
> 9_223_372_036_854_775_808 .. 18_446_744_073_709_551_615 ulong

See: https://dlang.org/spec/lex.html#integerliteral

What I am aiming at: Is the spec wrong or am I misunderstanding 
it and did this change recently?


More information about the Digitalmars-d-learn mailing list