-Wsign-conversion should consider control-flow sentive range and only warn if problematic numbers are possible
Open
clang:diagnostics
false-positive
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following code is perfectly fine, but currently generates a bogus warning:
```cpp
int f(unsigned);
int test(int i) {
if (i < 0)
return 0;
return f(i);
}
```
```
:7:14: warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
7 | return f(i);
| ~ ^
```
https://godbolt.org/z/6KzM1K36f
`i` can never be negative at that point (and I'm pretty sure other warnings know that), so there shouldn't be a warning when it gets converted to unsigned.
I have also filed a matching bug with gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123127
Contributor guide
Assessment
This issue has not been assessed yet.