digitalmars.D.learn - Bug or Feature: unsigned integer overflow
- Tobias Pankrath (7/8) Dec 13 2019 void main()
- berni44 (8/12) Dec 13 2019 You need to tell, that this is an unsigned long literal, else the
- Tobias Pankrath (6/23) Dec 14 2019 As far as I understand the spec, the type is inferred from the
- berni44 (6/9) Dec 14 2019 You are right. The implementation does not do what the specs tell
- Tobias Pankrath (2/12) Dec 14 2019 Thank you!
void main() { auto x = 9223372036854775808; // long.max + 1 }onlineapp.d(3): Error: signed integer overflowAccording to spec x should be of type ulong and this should compile? It indeed compiles if I add the uL postfix. Is this a bug or indented behaviour?
Dec 13 2019
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 }
Dec 13 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:As far as I understand the spec, the type is inferred from the value range: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 }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 ulongSee: 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?
Dec 14 2019
On Saturday, 14 December 2019 at 09:33:13 UTC, Tobias Pankrath wrote: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?You are right. The implementation does not do what the specs tell here. I filed a bug report: https://issues.dlang.org/show_bug.cgi?id=20449
Dec 14 2019
On Saturday, 14 December 2019 at 10:32:10 UTC, berni44 wrote:On Saturday, 14 December 2019 at 09:33:13 UTC, Tobias Pankrath wrote:Thank you!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?You are right. The implementation does not do what the specs tell here. I filed a bug report: https://issues.dlang.org/show_bug.cgi?id=20449
Dec 14 2019