llvm / llvm/llvm-project

-Wsign-conversion should consider control-flow sentive range and only warn if problematic numbers are possible

Open
#172,279 1 comment 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.