Skip to content

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

@RedBeard0531

Description

@RedBeard0531

The following code is perfectly fine, but currently generates a bogus warning:

int f(unsigned);
int test(int i) {
    if (i < 0)
        return 0;
    return f(i);
}
<source>: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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions