Skip to content

-Wimplicit-int-conversion feature request #171447

@steakhal

Description

@steakhal

PR #126846 started diagnosing unary negations. IMO that makes sense as in the following example it's going to narrow immediately, so the warning seems justified.

However, should we also warn for practically any other unary and binary operators that apply the standard integer promotion to int (if it was shorter than an int before)?
Like in i = i | 1;?

https://godbolt.org/z/3sEEWj8b7

unsigned short unary_negate(unsigned short i) {
    i = ~I; // we get the warning here
    return i;
}

unsigned short binary_or(unsigned short i) {
    i = i | 1; // why not also warn here?
    return i;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions