Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 14, 2019 Bug or Feature: unsigned integer overflow | ||||
---|---|---|---|---|
| ||||
void main()
{
auto x = 9223372036854775808; // long.max + 1
}
> onlineapp.d(3): Error: signed integer overflow
According 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?
|
December 14, 2019 Re: Bug or Feature: unsigned integer overflow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | 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
}
|
December 14, 2019 Re: Bug or Feature: unsigned integer overflow | ||||
---|---|---|---|---|
| ||||
Posted in reply to berni44 | 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? |
December 14, 2019 Re: Bug or Feature: unsigned integer overflow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | 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 |
December 14, 2019 Re: Bug or Feature: unsigned integer overflow | ||||
---|---|---|---|---|
| ||||
Posted in reply to berni44 | 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:
>> 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
Thank you!
|
Copyright © 1999-2021 by the D Language Foundation