Parsing of constants under windows
madmann91 opened this issue · 3 comments
Hexadecimal constants may result in wrong values under windows (e.g. 0x80000000
results in 2147483647
). This is because the parser relies on the standard library function strtol
, which returns LONG_MAX
in case the number is not representable in 32 bits. In this case 0x80000000
is treated as a positive constant, which explains the returned value.
We have two options:
- treat the constant
0x80000000
as a positive number, and emit a warning when an overflow occurs, - do as in C and treat the hexadecimal representation of the number as its binary representation - hence signless.
good catch.
As for now we don't have polymorphic literals. So let's give an error in the case of an under/overflow. We can change this behaviour as soon as we have polymorphic literals.
Can you plz double check my fix? It's just too easy to make mistakes...
I'd also like to add test cases before marking this issue as resolved.
I marking this issue as resolved since the patch fixes the issue and we now have a test case.