Issue 19432 - Cannot initialize ulong with decimal value above signed long range
Summary: Cannot initialize ulong with decimal value above signed long range
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2018-11-25 12:14 UTC by johanengelen
Modified: 2019-11-27 12:34 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description johanengelen 2018-11-25 12:14:16 UTC
Initialization of an ulong with a decimal within range, but outside long range, gives a "Error: signed integer overflow" compiler error.
Testcase:
```
enum a = 18446744073709551615; // 2^^64 - 1
ulong b = 18446744073709551615; // 2^^64 - 1
```
Comment 1 Stanislav Blinov 2018-11-25 12:40:10 UTC
That needs an "U" suffix, which is a little bit not obvious from the spec:

https://dlang.org/spec/lex.html#integerliteral
Comment 2 johanengelen 2018-11-25 13:44:51 UTC
Indeed, thanks.  Specifically 2.12.8
Comment 3 Răzvan Ștefănescu 2019-10-16 17:02:41 UTC
I don't consider this resolved. Unsigned long values were accepted before without error, I cannot tell for sure when this changed.

ulong x = 9223372036854775809; was considered valid code.

I don't see the point in forcing the user to decorate his numbers with data type suffixes.
Comment 4 Dlang Bot 2019-11-22 21:07:20 UTC
@benjones created dlang/dmd pull request #10607 "fix issue 19432 automatically interpret big int literals as " fixing this issue:

- fix issue 19432 automatically interpret big int literals as unsigned longs if they dont fit in a signed long

https://github.com/dlang/dmd/pull/10607
Comment 5 Dlang Bot 2019-11-22 21:07:54 UTC
@benjones created dlang/dlang.org pull request #2718 "fix issue 19432 automatically interpret big int literals as " fixing this issue:

- fix issue 19432 automatically interpret big int literals as unsigned longs if they dont fit in a signed long

https://github.com/dlang/dlang.org/pull/2718
Comment 6 Dlang Bot 2019-11-27 12:33:37 UTC
dlang/dlang.org pull request #2718 "fix issue 19432 automatically interpret big int literals as " was merged into master:

- ca4a016638b47d755c1e7d196b8bafeb2f023803 by Ben Jones:
  fix issue 19432 automatically interpret big int literals as unsigned longs if they dont fit in a signed long

https://github.com/dlang/dlang.org/pull/2718
Comment 7 Dlang Bot 2019-11-27 12:34:09 UTC
dlang/dmd pull request #10607 "fix issue 19432 automatically interpret big int literals as " was merged into master:

- b9443805651c40bb56250c195a3de70c9cdaa2f3 by Ben Jones:
  fix issue 19432 automatically interpret big int literals as unsigned longs if they dont fit in a signed long

https://github.com/dlang/dmd/pull/10607