Bug 19432 – Cannot initialize ulong with decimal value above signed long range

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-11-25T12:14:16Z
Last change time
2019-11-27T12:34:09Z
Keywords
pull
Assigned to
No Owner
Creator
johanengelen

Comments

Comment #0 by johanengelen — 2018-11-25T12:14:16Z
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 by stanislav.blinov — 2018-11-25T12:40:10Z
That needs an "U" suffix, which is a little bit not obvious from the spec: https://dlang.org/spec/lex.html#integerliteral
Comment #2 by johanengelen — 2018-11-25T13:44:51Z
Indeed, thanks. Specifically 2.12.8
Comment #3 by rumbu — 2019-10-16T17:02:41Z
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 by dlang-bot — 2019-11-22T21:07:20Z
@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 by dlang-bot — 2019-11-22T21:07:54Z
@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 by dlang-bot — 2019-11-27T12:33:37Z
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 by dlang-bot — 2019-11-27T12:34:09Z
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