Issue 164484
Summary Add a warning for lossy integer division of constants
Labels new issue
Assignees
Reporter RedBeard0531
    I was kinda surprised that `return 1 / 2;` produces [no warnings](https://godbolt.org/z/WbobMYoME), even with `-Weverything`. That feels like a natural way to write one half, for someone who isn't thinking of integers and truncating division. And since it seems like you would never _intentionally_ write that[0], it should have a warning. I know there are already some warnings where arithmetic with constants doesn't evaluate to the numeric result (eg due to overflow) and this seems to fit right in there. It could even become a single warning about any time that numeric results aren't preserved (excluding bitwise operators and common patterns like `-1ull` to get a bunch of 1 bits).


[0] Ignoring obfuscated code contests...
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to