Skip to content
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

Warn if implicit integer conversion truncates value #701

Open
ehaas opened this issue May 3, 2024 · 0 comments
Open

Warn if implicit integer conversion truncates value #701

ehaas opened this issue May 3, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ehaas
Copy link
Collaborator

ehaas commented May 3, 2024

unsigned char x = 1000;

We currently issue no warning; it should look something like:

test.c:1:19: warning: implicit conversion from 'int' to 'unsigned char' changes value from 1000 to 232 [-Wconstant-conversion]
unsigned char x = 1000;
                  ^

Value.intCast currently returns void on success; we can have it return a value that indicates whether truncation happens and then issue a diagnostic if so (similar to how Value.floatToInt is handled)

@ehaas ehaas added enhancement New feature or request good first issue Good for newcomers labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant