-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conform non-suffixed integer literals #5717
Conform non-suffixed integer literals #5717
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you for the fixes!
We don’t need to address in this PR, but the change does reveal that we are missing a check during coercion of integer literals when the literal is out of range.
for example, we should still warn when the user writes
int x=0xffffffffffff;
But this check can’t be done in the lexer and needs to happen during coerce().
Mark the PR as a breaking change because some corner case behaviors around literal types are changed. |
The |
Regarding coercion,
But there is a weird issue when coercing UINT64_MAX which I have written down here #5728 which I fill fix in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thank you for fixing the tests!
Fixes #5458.
Make non-suffixed integer literals conformant to the C++ standard. The type of a decimal non-suffixed integer literal is the first integer type from the list [
int
,int64_t
] which can represent the specified literal value. If the value cannot fit, the literal is represented as anuint64_t
and a warning is given. The type of hexadecimal non-suffixed integer literal is the first type from the list [int
,uint
,int64_t
,uint64_t
] that can represent the specified literal value. The current non-suffixed behavior forces all integer literals to be represented as signed 32 bit integers.The change consists of:
Unfortunately there is an edge case when parsing
-9223372036854775808
(smallest int64 value). Because the lexer handles the negative(-) part of the literal separately.9223372036854775808
is parsed by itself and it exceeds9223372036854775807
(largest int64 value), and a warning is emitted although it should not as-9223372036854775808
is within the range of int64 . When negation is parsed the value will still be properly assigned to-9223372036854775808
. This compiler warning is also seen in clang and gcc. A proper fix for this would require lexer changes.