Skip to content

[clang-tidy] Ignore modernize-use-integer-sign-comparison between signed wide type and unsigned narrow type #120867

@zufuliu

Description

@zufuliu

For following code (online at https://godbolt.org/z/evGzzTdb7), I'd like the checker emits no warnings for foo1 and foo2 (the narrow y implicitly promoted to int), also bar1 missed the warning even with -fsigned-char.

bool foo1(int x, unsigned char y) {
    return x == y;
}
bool foo2(int x, unsigned short y) {
    return x == y;
}
bool bar1(unsigned int x, char y) {
    return x == y;
}
bool bar2(unsigned int x, short y) {
    return x == y;
}

current output:

[<source>:2:12: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]](javascript:;)
    1 | bool foo1(int x, unsigned char y) {
    2 |     return x == y;
      |            ^ ~~  
      |            std::cmp_equal( , )
[<source>:5:12: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]](javascript:;)
    5 |     return x == y;
      |            ^ ~~  
      |            std::cmp_equal( , )
[<source>:11:12: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]](javascript:;)
   11 |     return x == y;
      |            ^ ~~  
      |            std::cmp_equal( , )
3 warnings generated.

CC @qt-tatiana as author of the checker (PR #113144).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions